How to block or download a pdf #1783
Replies: 4 comments 4 replies
|
as for JS there is: https://crawlee.dev/js/docs/examples/file-download |
|
Hi @danielvanmilgx, could you please provide a minimal code snippet that shows the error and/or desired functionality? |
|
I need a minimal example to demonstrate the issue. The error likely stems from missing dependencies or incorrect use of Playwright in the crawler setup. Let me walk through it. |
|
Navigation to a PDF fails because headless browser can't render it, so The good news is that this is currently being added in #2043: Once merged, it could look something like this: from crawlee.crawlers import FileDownloadCrawler, FileDownloadCrawlingContext
crawler = FileDownloadCrawler()
@crawler.router.default_handler
async def handler(context: FileDownloadCrawlingContext) -> None:
content = await context.http_response.read()
kvs = await context.get_key_value_store()
await kvs.set_value('sample.pdf', content, 'application/pdf')
await crawler.run(['https://example.com/sample.pdf'])If you need this today, load the website with If you only want to skip PDFs, use the await context.enqueue_links(exclude=[Glob('**/*.pdf')]) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello,
Are there working examples of blocking or downloading a pdf with Playwright crawler?
I keep getting errors like:
as for JS there is: https://crawlee.dev/js/docs/examples/file-download
All reactions