
ScraperCodeGenerator
Pricing
Pay per usage
Go to Store

ScraperCodeGenerator
An intelligent web scraping tool that automatically generates custom scraping code for any website.
0.0 (0)
Pricing
Pay per usage
0
Total users
1
Monthly users
1
Last modified
a day ago
You can access the ScraperCodeGenerator programmatically from your own 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 token4// Replace the '<YOUR_API_TOKEN>' with your token5const client = new ApifyClient({6 token: '<YOUR_API_TOKEN>',7});8
9// Prepare Actor input10const input = {11 "targetUrl": "https://books.toscrape.com/",12 "userGoal": "Get me a list of all the books on the first page. For each book, I want its title, price, star rating, and whether it is in stock.",13 "actors": [14 {15 "name": "cheerio-scraper",16 "enabled": true,17 "input": {18 "maxRequestRetries": 3,19 "requestTimeoutSecs": 30,20 "maxPagesPerCrawl": 1,21 "pageFunction": "async function pageFunction(context) {\n const { request, log, $ } = context;\n try {\n const title = $('title').text() || '';\n const html = $('html').html() || '';\n return {\n url: request.url,\n title: title,\n html: html\n };\n } catch (error) {\n log.error('Error in pageFunction:', error);\n return {\n url: request.url,\n title: '',\n html: ''\n };\n }\n}",22 "proxyConfiguration": {23 "useApifyProxy": true24 }25 }26 },27 {28 "name": "web-scraper",29 "enabled": false,30 "input": {31 "maxRequestRetries": 3,32 "requestTimeoutSecs": 30,33 "maxPagesPerCrawl": 1,34 "pageFunction": "async function pageFunction(context) {\n const { request, log, page } = context;\n try {\n const title = await page.title();\n const html = await page.content();\n return {\n url: request.url,\n title: title,\n html: html\n };\n } catch (error) {\n log.error('Error in pageFunction:', error);\n return {\n url: request.url,\n title: '',\n html: ''\n };\n }\n}",35 "proxyConfiguration": {36 "useApifyProxy": true37 }38 }39 },40 {41 "name": "website-content-crawler",42 "enabled": true,43 "input": {44 "maxCrawlPages": 1,45 "crawler": "playwright",46 "proxyConfiguration": {47 "useApifyProxy": true48 }49 }50 },51 {52 "name": "playwright-scraper",53 "enabled": false,54 "input": {55 "maxRequestRetries": 2,56 "requestTimeoutSecs": 45,57 "maxPagesPerCrawl": 1,58 "pageFunction": "async function pageFunction(context) {\n const { request, log, page } = context;\n try {\n const title = await page.title();\n const html = await page.content();\n return {\n url: request.url,\n title: title,\n html: html\n };\n } catch (error) {\n log.error('Error in pageFunction:', error);\n return {\n url: request.url,\n title: '',\n html: ''\n };\n }\n}",59 "proxyConfiguration": {60 "useApifyProxy": true61 }62 }63 }64 ]65};66
67// Run the Actor and wait for it to finish68const run = await client.actor("ohlava/scrapercodegenerator").call(input);69
70// Fetch and print Actor results from the run's dataset (if any)71console.log('Results from dataset');72console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);73const { items } = await client.dataset(run.defaultDatasetId).listItems();74items.forEach((item) => {75 console.dir(item);76});77
78// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs
ScraperCodeGenerator API in JavaScript
The Apify API client for JavaScript is the official library that allows you to use ScraperCodeGenerator 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: