Parsel crawler
Get data from every page on a site. Good for simple sites like blogs, news, or product listings, but it can't run client-side JavaScript. Uses Parsel, with native XPath and CSS selector support.
my_actor/main.py
my_actor/routes.py
my_actor/__main__.py
1"""Module defines the main entry point for the Apify Actor.2
3Feel free to modify this file to suit your specific needs.4
5To build Apify Actors, utilize the Apify SDK toolkit, read more at the official documentation:6https://docs.apify.com/sdk/python7"""8
9from __future__ import annotations10
11from apify import Actor12from crawlee.crawlers import ParselCrawler13
14from .routes import router15
16
17async def main() -> None:18 """Define a main entry point for the Apify Actor.19
20 This coroutine is executed using `asyncio.run()`, so it must remain an asynchronous function for proper execution.21 Asynchronous execution is required for communication with Apify platform, and it also enhances performance in22 the field of web scraping significantly.23 """24 # Enter the context of the Actor.25 async with Actor:26 # Retrieve the Actor input, and use default values if not provided.27 actor_input = await Actor.get_input() or {}28 start_urls = [29 url.get('url')30 for url in actor_input.get(31 'start_urls',32 [{'url': 'https://apify.com'}],33 )34 ]35
36 # Exit if no start URLs are provided.37 if not start_urls:38 Actor.log.info('No start URLs specified in Actor input, exiting...')39 await Actor.exit()40
41 # Create a crawler.42 crawler = ParselCrawler(43 # Limit the crawl to max requests. Remove or increase it for crawling all links.44 max_requests_per_crawl=10,45 # Set the request handler to the request router defined in routes.py.46 request_handler=router,47 )48
49 # Run the crawler with the starting requests.50 await crawler.run(start_urls)A template for web scraping data from websites starting from provided URLs using Python. The starting URLs are passed through the Actor's input schema, defined by the input schema . The template uses Crawlee for Python for efficient web crawling, handling each request through a user-defined handler that uses Parsel to extract data from the page. Enqueued URLs are managed in the request queue , and the extracted data is saved in a dataset for easy access.
- Apify SDK - a toolkit for building Apify Actors in Python.
- Crawlee for Python - a web scraping and browser automation library.
- Input schema - define and validate a schema for your Actor's input.
- Request queue - manage the URLs you want to scrape in a queue.
- Dataset - store and access structured data extracted from web pages.
- Parsel - a library for pulling data out of HTML and XML files.
- Video introduction to Python SDK
- Webinar introducing to Crawlee for Python
- Apify Python SDK documentation
- Crawlee for Python documentation
- Python tutorials in Academy
- Integration with Make, GitHub, Zapier, Google Drive, and other apps
- Video guide on getting scraped data using Apify API
- A short guide on how to build web scrapers using code templates:
BeautifulSoup crawler
Get data from every page on a site. Good for simple sites like blogs, news, or product listings, but it can't run client-side JavaScript. Uses BeautifulSoup, Python's most popular HTML parser.
Empty Python Actor
An Actor with the Apify SDK set up, so you can build any tool you need.
Python one-page scraper
Get data from one web page with BeautifulSoup. The simplest way to start scraping.
Python project managed by uv
A general-purpose Python Actor with its project and dependencies managed by the uv package manager. A minimal starting point for any use case.
Python multi-page scraper
Get data from multiple web pages with BeautifulSoup. Fast and light for simple sites.
Python Playwright scraper
A real-browser scraper that gets data HTTP scrapers miss. Good for social feeds, dashboards, or single-page apps.