Quick Start
Get up and running with Easy Scrape API in minutes. This guide will walk you through your first scraping request.
Prerequisites
- API key from RapidAPI
- Basic understanding of JavaScript (for custom scripts)
Your First Requests
1. Basic URL Validation
curl -X POST "https://easy-scrape-api.p.rapidapi.com/api/scrape" \
-H "X-RapidAPI-Key: YOUR_RAPIDAPI_KEY" \
-H "X-RapidAPI-Host: easy-scrape-api.rapidapi.com" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com"
}'
2. Extract Page Title
curl -X POST "https://easy-scrape-api.p.rapidapi.com/api/scrape" \
-H "X-RapidAPI-Key: YOUR_RAPIDAPI_KEY" \
-H "X-RapidAPI-Host: easy-scrape-api.rapidapi.com" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"script": "const title = await page.title(); return { title };"
}'
Response:
{
"message": "Script executed successfully",
"data": {
"title": "Example Domain"
},
"executionTime": 1250,
"logs": []
}
JavaScript Examples
warning
The examples below are shown in JavaScript format for readability. When sending a script to the Easy Scrape API, you must provide it as a string (e.g., inside the script field of your JSON request). If you need help converting your code, check out our Online Code Parser Tool to easily convert JavaScript code to a string ready for the API.
Extract Multiple Elements
// Navigate to the page
await page.goto(targetUrl);
// Wait for content to load
await page.waitForSelector('h1');
// Extract data
const data = await page.evaluate(() => {
return {
title: document.querySelector('h1')?.textContent,
description: document.querySelector('meta[name="description"]')?.content,
links: Array.from(document.querySelectorAll('a')).map(a => ({
text: a.textContent,
href: a.href
})).slice(0, 5) // First 5 links
};
});
return data;
Using Cheerio for HTML Parsing
// Get page HTML
await page.goto(targetUrl);
const html = await page.content();
// Use Cheerio to parse
const $ = cheerio.load(html);
const products = [];
$('.product').each((i, el) => {
products.push({
name: $(el).find('.product-name').text(),
price: $(el).find('.price').text(),
image: $(el).find('img').attr('src')
});
});
return { products };
Common Patterns
Wait for Dynamic Content
await page.goto(targetUrl);
// Wait for specific element
await page.waitForSelector('.dynamic-content');
// Or wait for network to be idle
await page.waitForLoadState('networkidle');
const content = await page.textContent('.dynamic-content');
return { content };
Handle Forms
await page.goto(targetUrl);
// Fill and submit a form
await page.type('#search-input', 'your search term');
await page.click('#search-button');
// Wait for results
await page.waitForSelector('.search-results');
const results = await page.$$eval('.result-item', items =>
items.map(item => ({
title: item.querySelector('.title')?.textContent,
link: item.querySelector('a')?.href
}))
);
return { results };
Output Formats
JSON Output (Default)
Perfect for data processing and integration with other systems:
{
"url": "https://example.com",
"outputFormat": "json"
}
HTML Output
Great for displaying formatted results:
{
"url": "https://example.com",
"script": "return '<h1>Scraped Data</h1><p>Content here</p>';",
"outputFormat": "html"
}
Next Steps
- Explore Platform Integrations for no-code solutions
- Check out API Reference for detailed documentation
- Browse Tutorials for real-world examples
Pro Tips
- Use
console.log()in your scripts to debug - logs appear in the response - Use
page.waitForSelector()for dynamic content that loads after page load