My Actr Testing avatar
My Actr Testing
Try for free

No credit card required

View all Actors
My Actr Testing

My Actr Testing

xrhibiyftd/my-actr-testing
Try for free

No credit card required

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 Apify API token
4client = ApifyClient("<YOUR_API_TOKEN>")
5
6# Prepare the Actor input
7run_input = {
8    "runMode": "PRODUCTION",
9    "startUrls": [{ "url": "https://www.example.com" }],
10    "pageFunction": """// The function accepts a single argument: the \"context\" object.
11// For a complete list of its properties and functions,
12// see https://apify.com/apify/web-scraper#page-function 
13async function pageFunction(context) {
14    // This statement works as a breakpoint when you're trying to debug your code. Works only with Run mode: DEVELOPMENT!
15    // debugger; 
16
17    // jQuery is handy for finding DOM elements and extracting data from them.
18    // To use it, make sure to enable the \"Inject jQuery\" option.
19    const $ = context.jQuery;
20    const pageTitle = $('title').first().text();
21    const h1 = $('h1').first().text();
22    const first_h2 = $('h2').first().text();
23    const random_text_from_the_page = $('p').first().text();
24
25
26    // Print some information to actor log
27    context.log.info(`URL: ${context.request.url}, TITLE: ${pageTitle}`);
28
29    // Manually add a new page to the queue for scraping.
30   await context.enqueueRequest({ url: 'http://www.example.com' });
31
32    // Return an object with the data extracted from the page.
33    // It will be stored to the resulting dataset.
34    return {
35        url: context.request.url,
36        pageTitle,
37        h1,
38        first_h2,
39        random_text_from_the_page
40    };
41}""",
42    "proxyConfiguration": { "useApifyProxy": True },
43    "proxyRotation": "UNTIL_FAILURE",
44    "initialCookies": [],
45    "waitUntil": ["networkidle2"],
46    "preNavigationHooks": """// We need to return array of (possibly async) functions here.
47// The functions accept two arguments: the \"crawlingContext\" object
48// and \"gotoOptions\".
49[
50    async (crawlingContext, gotoOptions) => {
51        // ...
52    },
53]
54""",
55    "postNavigationHooks": """// We need to return array of (possibly async) functions here.
56// The functions accept a single argument: the \"crawlingContext\" object.
57[
58    async (crawlingContext) => {
59        // ...
60    },
61]""",
62    "breakpointLocation": "NONE",
63    "customData": {},
64}
65
66# Run the Actor and wait for it to finish
67run = client.actor("xrhibiyftd/my-actr-testing").call(run_input=run_input)
68
69# Fetch and print Actor results from the run's dataset (if there are any)
70for item in client.dataset(run["defaultDatasetId"]).iterate_items():
71    print(item)
Developer
Maintained by Community
Actor metrics
  • 6 monthly users
  • 100.0% runs succeeded
  • 0.0 days response time
  • Created in Jan 2024
  • Modified 3 months ago
Categories