Rust Input Function Example avatar

Rust Input Function Example

Try for free

No credit card required

Go to Store
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 JavaScript 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.

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

Rust Input Function Example API in JavaScript

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

Install the apify-client

npm install apify-client

Other API clients include:

Developer
Maintained by Community

Actor Metrics

  • 1 monthly user

  • 2 stars

  • 83% runs succeeded

  • Created in Dec 2023

  • Modified 19 days ago

Categories