Skip to main content

Crawl all links on website

This example uses the enqueue_links() helper to add new links to the RequestQueue as the crawler navigates from page to page. By automatically discovering and enqueuing all links on a given page, the crawler can systematically scrape an entire website. This approach is ideal for web scraping tasks where you need to collect data from multiple interconnected pages.


If no options are given, by default the method will only add links that are under the same subdomain. This behavior can be controlled with the strategy option. You can find more info about this option in the Crawl website with relative links example.

import asyncio

from crawlee.beautifulsoup_crawler import BeautifulSoupCrawler, BeautifulSoupCrawlingContext

async def main() -> None:
crawler = BeautifulSoupCrawler(
# Limit the crawl to max requests. Remove or increase it for crawling all links.

# Define the default request handler, which will be called for every request.
async def request_handler(context: BeautifulSoupCrawlingContext) -> None:'Processing {context.request.url} ...')

# Enqueue all links found on the page.
await context.enqueue_links()

# Run the crawler with the initial list of requests.

if __name__ == '__main__':