![Web Scraper avatar](https://images.apifyusercontent.com/AphVzIXRBUXsO0jvtqZG899mSuWDqpjxK_Kdf4Upz0Q/rs:fill:250:250/aHR0cHM6Ly9hcGlmeS1pbWFnZS11cGxvYWRzLXByb2QuczMuYW1hem9uYXdzLmNvbS9tb0pSTFJjODVBaXRBcnBOTi9abjh2YldUaWthN2FuQ1FNbi1TRC0wMi0wMi5wbmc.webp)
Web Scraper
Try for free
No credit card required
View all Actors![Web Scraper](https://images.apifyusercontent.com/AphVzIXRBUXsO0jvtqZG899mSuWDqpjxK_Kdf4Upz0Q/rs:fill:250:250/aHR0cHM6Ly9hcGlmeS1pbWFnZS11cGxvYWRzLXByb2QuczMuYW1hem9uYXdzLmNvbS9tb0pSTFJjODVBaXRBcnBOTi9abjh2YldUaWthN2FuQ1FNbi1TRC0wMi0wMi5wbmc.webp)
![Web Scraper](https://images.apifyusercontent.com/AphVzIXRBUXsO0jvtqZG899mSuWDqpjxK_Kdf4Upz0Q/rs:fill:250:250/aHR0cHM6Ly9hcGlmeS1pbWFnZS11cGxvYWRzLXByb2QuczMuYW1hem9uYXdzLmNvbS9tb0pSTFJjODVBaXRBcnBOTi9abjh2YldUaWthN2FuQ1FNbi1TRC0wMi0wMi5wbmc.webp)
Web Scraper
apify/web-scraper
Try for free
No credit card required
Crawls arbitrary websites using the Chrome browser and extracts data from pages using JavaScript code. The Actor supports both recursive crawling and lists of URLs and automatically manages concurrency for maximum performance. This is Apify's basic tool for web crawling and scraping.
Do you want to learn more about this Actor?
Get a demoThe 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
1from apify_client import ApifyClient
2
3# Initialize the ApifyClient with your Apify API token
4client = ApifyClient("<YOUR_API_TOKEN>")
5
6# Prepare the Actor input
7run_input = {
8 "runMode": "DEVELOPMENT",
9 "startUrls": [{ "url": "https://crawlee.dev" }],
10 "linkSelector": "a[href]",
11 "globs": [{ "glob": "https://crawlee.dev/*/*" }],
12 "pseudoUrls": [],
13 "excludes": [{ "glob": "/**/*.{png,jpg,jpeg,pdf}" }],
14 "pageFunction": """// The function accepts a single argument: the \"context\" object.
15// For a complete list of its properties and functions,
16// see https://apify.com/apify/web-scraper#page-function
17async function pageFunction(context) {
18 // This statement works as a breakpoint when you're trying to debug your code. Works only with Run mode: DEVELOPMENT!
19 // debugger;
20
21 // jQuery is handy for finding DOM elements and extracting data from them.
22 // To use it, make sure to enable the \"Inject jQuery\" option.
23 const $ = context.jQuery;
24 const pageTitle = $('title').first().text();
25 const h1 = $('h1').first().text();
26 const first_h2 = $('h2').first().text();
27 const random_text_from_the_page = $('p').first().text();
28
29
30 // Print some information to actor log
31 context.log.info(`URL: ${context.request.url}, TITLE: ${pageTitle}`);
32
33 // Manually add a new page to the queue for scraping.
34 await context.enqueueRequest({ url: 'http://www.example.com' });
35
36 // Return an object with the data extracted from the page.
37 // It will be stored to the resulting dataset.
38 return {
39 url: context.request.url,
40 pageTitle,
41 h1,
42 first_h2,
43 random_text_from_the_page
44 };
45}""",
46 "proxyConfiguration": { "useApifyProxy": True },
47 "initialCookies": [],
48 "waitUntil": ["networkidle2"],
49 "preNavigationHooks": """// We need to return array of (possibly async) functions here.
50// The functions accept two arguments: the \"crawlingContext\" object
51// and \"gotoOptions\".
52[
53 async (crawlingContext, gotoOptions) => {
54 // ...
55 },
56]
57""",
58 "postNavigationHooks": """// We need to return array of (possibly async) functions here.
59// The functions accept a single argument: the \"crawlingContext\" object.
60[
61 async (crawlingContext) => {
62 // ...
63 },
64]""",
65 "breakpointLocation": "NONE",
66 "customData": {},
67}
68
69# Run the Actor and wait for it to finish
70run = client.actor("apify/web-scraper").call(run_input=run_input)
71
72# Fetch and print Actor results from the run's dataset (if there are any)
73print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
74for item in client.dataset(run["defaultDatasetId"]).iterate_items():
75 print(item)
76
77# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start
Developer
Maintained by Apify
Actor metrics
- 2.6k monthly users
- 155 stars
- 99.9% runs succeeded
- 6.6 days response time
- Created in Mar 2019
- Modified 23 days ago
Categories