Rust Input Function Example avatar

Rust Input Function Example

Try for free

No credit card required

View all Actors
Rust Input Function Example

Rust Input Function Example

lukaskrivka/rust-input-function-example
Try for free

No credit card required

Dynamically compile and run input-provided page function. Like Cheerio Scraper but in Rust.

You can access the Rust Input Function Example programmatically from your own Python applications by using the Apify API. You can also choose the language preference from below. To use the Apify API, you’ll need an Apify account and your API token, found in Integrations settings in Apify Console.

1from apify_client import ApifyClient
2
3# Initialize the ApifyClient with your Apify API token
4# Replace '<YOUR_API_TOKEN>' with your token.
5client = ApifyClient("<YOUR_API_TOKEN>")
6
7# Prepare the Actor input
8run_input = {
9    "url": "https://apify.com",
10    "page_function": """use serde_json::{Value,json};
11use scraper::{Html, Selector};
12
13fn selector_to_text(document: &Html, selector: &str) -> Option<String> {
14    document
15        .select(&Selector::parse(selector).unwrap())
16        .next()
17        .map(|el| el.text().next().unwrap().into() )
18}
19
20#[no_mangle]
21pub fn page_function (document: &Html) -> Value { 
22    println!(\"page_function starting\");
23
24    let title = selector_to_text(&document, \"title\");
25    println!(\"extracted title: {:?}\", title);
26
27    let header = selector_to_text(&document, \"h1\");
28    println!(\"extracted header: {:?}\", header);
29
30    let companies_using_apify = document
31        .select(&Selector::parse(\".Logos__container\").unwrap())
32        .next().unwrap()
33        .select(&Selector::parse(\"img\").unwrap())
34        .map(|el| el.value().attr(\"alt\").unwrap().to_string())
35        .collect::<Vec<String>>();
36
37    println!(\"extracted companies_using_apify: {:?}\", companies_using_apify);
38
39    let output = json!({
40        \"title\": title,
41        \"header\": header,
42        \"companies_using_apify\": companies_using_apify,
43    });
44    println!(\"inside pageFunction output: {:?}\", output);
45    output
46}""",
47}
48
49# Run the Actor and wait for it to finish
50run = client.actor("lukaskrivka/rust-input-function-example").call(run_input=run_input)
51
52# Fetch and print Actor results from the run's dataset (if there are any)
53print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
54for item in client.dataset(run["defaultDatasetId"]).iterate_items():
55    print(item)
56
57# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

Rust Input Function Example API in Python

The Apify API client for Python is the official library that allows you to use Rust Input Function Example API in Python, providing convenience functions and automatic retries on errors.

Install the apify-client

pip install apify-client

Other API clients include:

Developer
Maintained by Community
Actor metrics
  • 1 monthly user
  • 2 stars
  • 100.0% runs succeeded
  • Created in Dec 2023
  • Modified 10 months ago