Puppeteer Scraper avatar
Puppeteer Scraper
Try for free

No credit card required

View all Actors
Puppeteer Scraper

Puppeteer Scraper

apify/puppeteer-scraper
Try for free

No credit card required

Crawls websites with the headless Chrome and Puppeteer library using a provided server-side Node.js code. This crawler is an alternative to apify/web-scraper that gives you finer control over the process. Supports both recursive crawling and list of URLs. Supports login to website.

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

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    "startUrls": [{ "url": "https://crawlee.dev" }],
9    "globs": [{ "glob": "https://crawlee.dev/*/*" }],
10    "pseudoUrls": [],
11    "excludes": [{ "glob": "/**/*.{png,jpg,jpeg,pdf}" }],
12    "linkSelector": "a",
13    "pageFunction": """async function pageFunction(context) {
14    const { page, request, log } = context;
15    const title = await page.title();
16    log.info(`URL: ${request.url} TITLE: ${title}`);
17    return {
18        url: request.url,
19        title
20    };
21}""",
22    "proxyConfiguration": { "useApifyProxy": True },
23    "initialCookies": [],
24    "waitUntil": ["networkidle2"],
25    "preNavigationHooks": """// We need to return array of (possibly async) functions here.
26// The functions accept two arguments: the \"crawlingContext\" object
27// and \"gotoOptions\".
28[
29    async (crawlingContext, gotoOptions) => {
30        const { page } = crawlingContext;
31        // ...
32    },
33]""",
34    "postNavigationHooks": """// We need to return array of (possibly async) functions here.
35// The functions accept a single argument: the \"crawlingContext\" object.
36[
37    async (crawlingContext) => {
38        const { page } = crawlingContext;
39        // ...
40    },
41]""",
42    "customData": {},
43}
44
45# Run the Actor and wait for it to finish
46run = client.actor("apify/puppeteer-scraper").call(run_input=run_input)
47
48# Fetch and print Actor results from the run's dataset (if there are any)
49print("๐Ÿ’พ Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
50for item in client.dataset(run["defaultDatasetId"]).iterate_items():
51    print(item)
52
53# ๐Ÿ“š Want to learn more ๐Ÿ“–? Go to โ†’ https://docs.apify.com/api/client/python/docs/quick-start
Developer
Maintained by Apify
Actor metrics
  • 274 monthly users
  • 34 stars
  • 99.8% runs succeeded
  • 78 days response time
  • Created in Apr 2019
  • Modified about 1 month ago