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

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

You might also like these Actors