26 lines
722 B
Python
26 lines
722 B
Python
import asyncio
|
|
|
|
from crawlee.crawlers import BeautifulSoupCrawler, BeautifulSoupCrawlingContext
|
|
|
|
|
|
async def main() -> None:
|
|
crawler = BeautifulSoupCrawler(max_requests_per_crawl=10)
|
|
|
|
@crawler.router.default_handler
|
|
async def request_handler(context: BeautifulSoupCrawlingContext) -> None:
|
|
context.log.info(f'Processing {context.request.url}.')
|
|
|
|
# See the `EnqueueStrategy` type alias for more strategy options.
|
|
# highlight-next-line
|
|
await context.enqueue_links(
|
|
# highlight-next-line
|
|
strategy='same-domain',
|
|
# highlight-next-line
|
|
)
|
|
|
|
await crawler.run(['https://crawlee.dev/'])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(main())
|