Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new crawler.exportData helper #64

Open
B4nan opened this issue Nov 23, 2023 · 0 comments
Open

Use new crawler.exportData helper #64

B4nan opened this issue Nov 23, 2023 · 0 comments

Comments

@B4nan
Copy link

B4nan commented Nov 23, 2023

Hello from the crawlee team!

Just a small suggestion, I was taking a peek at the code and saw you do this to create a data bundle at the end.

gpt-crawler/src/core.ts

Lines 115 to 129 in 27b65d3

export async function write(config: Config) {
configSchema.parse(config);
const jsonFiles = await glob("storage/datasets/default/*.json", {
absolute: true,
});
const results = [];
for (const file of jsonFiles) {
const data = JSON.parse(await readFile(file, "utf-8"));
results.push(data);
}
await writeFile(config.outputFileName, JSON.stringify(results, null, 2));
}

We recently added a new helper that does exactly the same:

https://crawlee.dev/api/basic-crawler/class/BasicCrawler#exportData

So you could replace the whole function with a simple crawler.exportData(config.outputFileName) call, and it will support both JSON and CSV automatically (based on the file extension).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant