function (input, cheerio) {
let m = input.match(/"@type":"aggregateRating","ratingValue":((:?\d*\.)?\d+)/);
return m && m[1] ? m[1] : '';
}
function (input, cheerio) {
let $ = cheerio.load(input);
return { title: $('#title').text().trim() }
}
Grab extracted results from .extractor json property of ScrapeNinja response. Leave empty to parse everything on your side.
.body
property) from the API response (reduces response size)..info.headers
property) from the API response (reduces response size).Raw ScrapeNinja Response:
Quick video overview of the sandbox:
Code Generator
import fetch from 'node-fetch';
const url = 'https://scrapeninja.apiroad.net/scrape';
const PAYLOAD = {
"url": "https://letterboxd.com/film/inception/",
"method": "GET",
"retryNum": 1,
"geo": "us",
"extractor": "function (input, cheerio) {\n let m = input.match(/\"@type\":\"aggregateRating\",\"ratingValue\":((:?\\d*\\.)?\\d+)/);\n return m && m[1] ? m[1] : '';\n}"
};
const options = {
method: 'POST',
headers: {
'content-type': 'application/json',
// get your key at https://apiroad.net/marketplace/apis/scrapeninja
'X-Apiroad-Key': 'YOUR-KEY',
},
body: JSON.stringify(PAYLOAD)
};
try {
let res = await fetch(url, options);
let resJson = await res.json();
// Basic error handling. Modify if neccessary
if (!resJson.info || ![200, 404].includes(resJson.info.statusCode)) {
throw new Error(JSON.stringify(resJson));
}
console.log('target website response status: ', resJson.info.statusCode);
console.log('target website response body: ', resJson.body);
} catch (e) {
console.error(e);
}
Launching the scraper in your own Node.js environment:
(async () => { [CODE GOES HERE] } )();
. Check your Node.js version: node -v
.
Step 1. Create project folder, initialize empty npm project, and install node-fetch
mkdir your-project-folder && \ cd "$_" && \ npm i -g create-esnext && \ npm init esnext && \ npm i node-fetch -y
Step 2. Copy&paste the code above
Create new empty file like scraper.js
and paste the code to this file.
Step 3. Launch
node ./scraper.js
Sandbox FAQ
What is the ScrapeNinja Sandbox?
The ScrapeNinja Live Sandbox is an online tool designed to swiftly test the scraping capabilities of a specific target website using the ScrapeNinja Scraping API. It eliminates the need for coding or setting up a local environment. Our goal in creating the Sandbox was to simplify the process of exploring how to scrape a specific website, test various proxy countries for that target, and later bootstrap your project faster with the code generation feature provided by the Sandbox.
Is the ScrapeNinja Sandbox a paid service?
While the ScrapeNinja API operates on a subscription model, offering both free and paid plans, the ScrapeNinja Sandbox is currently available for free. This allows you to fully test its capabilities without any subscription. We hope you find the Sandbox a valuable tool for exploring the ScrapeNinja API.