BeautifulSoup Scraper
Try for free
No credit card required
View all Actors
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 more
Node.js
Python
curl
1import { ApifyClient } from 'apify-client';
2
3// Initialize the ApifyClient with your Apify 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 console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
35 const { items } = await client.dataset(run.defaultDatasetId).listItems();
36 items.forEach((item) => {
37 console.dir(item);
38 });
39})();
40
41// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs
Developer
Maintained by Apify
Actor metrics
- 33 monthly users
- 96.3% runs succeeded
- 0.0 days response time
- Created in Jul 2023
- Modified 6 months ago
Categories