BeautifulSoup Scraper avatar
BeautifulSoup Scraper
Try for free

No credit card required

View all Actors
BeautifulSoup Scraper

BeautifulSoup Scraper

apify/beautifulsoup-scraper
Try for free

No credit card required

Crawls websites using raw HTTP requests. It parses the HTML with the BeautifulSoup library and extracts data from the pages using Python code. Supports both recursive crawling and lists of URLs. This Actor is a Python alternative to Cheerio Scraper.

The code examples below show how to run the Actor and get its results. To run the code, you need to have an Apify account. Replace <YOUR_API_TOKEN> in the code with your API token, which you can find under Settings > Integrations in Apify Console. Learn mode

Node.js

Python

curl

1from apify_client import ApifyClient
2
3# Initialize the ApifyClient with your API token
4client = ApifyClient("<YOUR_API_TOKEN>")
5
6# Prepare the Actor input
7run_input = {
8    "startUrls": [{ "url": "https://crawlee.dev" }],
9    "maxCrawlingDepth": 1,
10    "requestTimeout": 10,
11    "linkSelector": "a[href]",
12    "linkPatterns": [".*crawlee\\.dev.*"],
13    "pageFunction": """from typing import Any
14
15# See the context section in readme to find out what fields you can access 
16# https://apify.com/vdusek/beautifulsoup-scraper#context    
17def page_function(context: Context) -> Any:
18    url = context.request['url']
19    title = context.soup.title.string if context.soup.title else None
20    return {'url': url, 'title': title}
21""",
22    "soupFeatures": "html.parser",
23    "proxyConfiguration": { "useApifyProxy": True },
24}
25
26# Run the Actor and wait for it to finish
27run = client.actor("apify/beautifulsoup-scraper").call(run_input=run_input)
28
29# Fetch and print Actor results from the run's dataset (if there are any)
30for item in client.dataset(run["defaultDatasetId"]).iterate_items():
31    print(item)
Developer
Apify logo Maintained by Apify
Actor metrics
  • 121 monthly users
  • 98.5% runs succeeded
  • 7.8 days response time
  • Modified 3 months ago

You might also like these Actors