Skip to main content

Request Examples

Complete collection of request examples for different use cases and scenarios with Easy Scrape API.

Basic Examples

Simple URL Validation

Test if a URL is accessible:

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://httpbin.org/get"
}'

Extract Page Title

{
"url": "https://example.com",
"script": "const title = await page.title(); return { title };"
}

Get Page Metadata

{
"url": "https://news-site.com",
"script": "const metadata = await page.evaluate(() => ({ title: document.title, description: document.querySelector('meta[name=\"description\"]')?.content, keywords: document.querySelector('meta[name=\"keywords\"]')?.content, author: document.querySelector('meta[name=\"author\"]')?.content, ogTitle: document.querySelector('meta[property=\"og:title\"]')?.content, ogImage: document.querySelector('meta[property=\"og:image\"]')?.content })); return metadata;"
}

E-commerce Examples

Product Information

{
"url": "https://shop.example.com/product/123",
"script": "await page.waitForSelector('.product-info'); const product = await page.evaluate(() => ({ name: document.querySelector('h1, .product-name')?.textContent?.trim(), price: document.querySelector('.price, .current-price')?.textContent?.trim(), originalPrice: document.querySelector('.original-price')?.textContent?.trim(), inStock: !document.querySelector('.out-of-stock'), rating: document.querySelector('.rating')?.textContent?.trim(), reviews: document.querySelector('.review-count')?.textContent?.trim(), description: document.querySelector('.description')?.textContent?.trim(), images: Array.from(document.querySelectorAll('.product-images img')).map(img => img.src).slice(0, 5) })); return product;"
}

Price Monitoring

{
"url": "https://retailer.com/product/laptop",
"script": "try { await page.waitForSelector('.price', { timeout: 10000 }); const priceData = await page.evaluate(() => { const priceEl = document.querySelector('.price, .current-price'); const stockEl = document.querySelector('.stock-status, .availability'); return { productName: document.querySelector('h1')?.textContent?.trim(), currentPrice: priceEl?.textContent?.trim(), numericPrice: parseFloat(priceEl?.textContent?.replace(/[^0-9.]/g, '') || '0'), currency: priceEl?.textContent?.match(/[$€£¥]/)?.[0] || '$', inStock: stockEl ? !stockEl.textContent.toLowerCase().includes('out') : true, stockText: stockEl?.textContent?.trim(), lastChecked: new Date().toISOString() }; }); return priceData; } catch (error) { return { error: error.message, timestamp: new Date().toISOString() }; }"
}

Content Extraction

News Article

{
"url": "https://news-site.com/article/123",
"script": "await page.waitForSelector('article, .article-content'); const article = await page.evaluate(() => ({ headline: document.querySelector('h1, .headline')?.textContent?.trim(), author: document.querySelector('.author, .byline')?.textContent?.trim(), publishDate: document.querySelector('.date, .published-date')?.textContent?.trim(), content: document.querySelector('.article-body, .content')?.textContent?.trim(), tags: Array.from(document.querySelectorAll('.tag, .category')).map(tag => tag.textContent?.trim()), readingTime: document.querySelector('.reading-time')?.textContent?.trim(), summary: document.querySelector('.summary, .excerpt')?.textContent?.trim() })); return article;"
}

Blog Post Collection

{
"url": "https://blog.example.com",
"script": "await page.waitForSelector('.post-list, .blog-posts'); const posts = await page.$$eval('.post-item, .blog-post', items => items.slice(0, 10).map(item => ({ title: item.querySelector('h2, h3, .post-title')?.textContent?.trim(), excerpt: item.querySelector('.excerpt, .summary')?.textContent?.trim(), author: item.querySelector('.author')?.textContent?.trim(), date: item.querySelector('.date, .published')?.textContent?.trim(), link: item.querySelector('a')?.href, image: item.querySelector('img')?.src, tags: Array.from(item.querySelectorAll('.tag')).map(tag => tag.textContent?.trim()) }))); return { posts, totalFound: posts.length };"
}

Social Media Examples

Public Posts (Generic)

{
"url": "https://social-platform.com/user/profile",
"script": "await page.waitForSelector('.post, .tweet, .update'); const posts = await page.$$eval('.post, .tweet, .update', items => items.slice(0, 20).map(item => ({ text: item.querySelector('.post-text, .content')?.textContent?.trim(), author: item.querySelector('.author, .username')?.textContent?.trim(), timestamp: item.querySelector('.timestamp, .date')?.textContent?.trim(), likes: item.querySelector('.likes-count')?.textContent?.trim(), shares: item.querySelector('.shares-count, .retweets')?.textContent?.trim(), replies: item.querySelector('.replies-count')?.textContent?.trim(), hashtags: (item.textContent?.match(/#\\w+/g) || []), mentions: (item.textContent?.match(/@\\w+/g) || []) }))); return { posts, scrapedAt: new Date().toISOString() };"
}

Advanced Techniques

Handle Dynamic Content

{
"url": "https://spa-website.com/data",
"script": "await page.waitForFunction(() => { return window.dataLoaded === true || document.querySelector('.loaded-content'); }, { timeout: 15000 }); await page.waitForSelector('.dynamic-content'); const data = await page.evaluate(() => ({ content: document.querySelector('.dynamic-content')?.textContent?.trim(), loadTime: window.performance?.now(), dataReady: window.dataLoaded || false })); return data;"
}

Form Interaction

{
"url": "https://search-site.com",
"script": "await page.type('#search-input', 'javascript tutorials'); await page.click('#search-button'); await page.waitForSelector('.search-results'); const results = await page.$$eval('.result-item', items => items.slice(0, 10).map(item => ({ title: item.querySelector('.result-title')?.textContent?.trim(), snippet: item.querySelector('.result-snippet')?.textContent?.trim(), url: item.querySelector('.result-link')?.href }))); return { searchQuery: 'javascript tutorials', results };"
}

Multiple Page Navigation

{
"url": "https://multi-page-site.com",
"script": "const allData = []; await page.waitForSelector('.content'); let pageNum = 1; const maxPages = 3; while (pageNum <= maxPages) { console.log(`Scraping page ${pageNum}...`); const pageData = await page.$$eval('.item', items => items.map(item => ({ title: item.querySelector('.title')?.textContent?.trim(), content: item.querySelector('.content')?.textContent?.trim(), page: currentPage }))); allData.push(...pageData); const nextButton = await page.$('.next-page, .pagination-next'); if (!nextButton || pageNum >= maxPages) break; await nextButton.click(); await page.waitForSelector('.content'); pageNum++; } return { data: allData, pagesScraped: pageNum };"
}

HTML Output Examples

Formatted Report

{
"url": "https://data-source.com",
"outputFormat": "html",
"script": "const data = await page.evaluate(() => ({ title: document.title, items: Array.from(document.querySelectorAll('.item')).slice(0, 10).map(item => ({ name: item.querySelector('.name')?.textContent?.trim(), value: item.querySelector('.value')?.textContent?.trim() })) })); const html = `<!DOCTYPE html><html><head><title>Scraping Report - ${data.title}</title><style>body { font-family: Arial, sans-serif; margin: 20px; } .header { background: #f0f0f0; padding: 10px; } .item { border-bottom: 1px solid #ccc; padding: 10px; } .value { font-weight: bold; color: #007acc; }</style></head><body><div class=\"header\"><h1>Data from: ${data.title}</h1><p>Scraped on: ${new Date().toLocaleString()}</p></div><div class=\"content\">${data.items.map(item => `<div class=\"item\"><strong>${item.name}</strong>: <span class=\"value\">${item.value}</span></div>`).join('')}</div></body></html>`; return html;"
}

Multi-line Script Examples

For better readability when working with longer scripts, you can format them as escaped strings:

Complex E-commerce Scraping (Formatted for Readability)

{
"url": "https://complex-shop.com/products",
"script": "\nawait page.waitForSelector('.product-grid');\n\nconst products = [];\nconst productElements = await page.$$('.product-card');\n\nfor (let i = 0; i < Math.min(productElements.length, 20); i++) {\n const element = productElements[i];\n const product = await element.evaluate(el => {\n const name = el.querySelector('.product-name')?.textContent?.trim();\n const price = el.querySelector('.price')?.textContent?.trim();\n const image = el.querySelector('img')?.src;\n const link = el.querySelector('a')?.href;\n const rating = el.querySelector('.rating')?.textContent?.trim();\n \n return { name, price, image, link, rating };\n });\n \n if (product.name && product.price) {\n products.push(product);\n }\n}\n\nreturn {\n products,\n totalFound: products.length,\n scrapedAt: new Date().toISOString()\n};"
}

Script Parameter Examples

Using script Parameter (Simple Scripts)

For straightforward scripts without complex quotes or special characters:

{
"url": "https://example.com",
"script": "const title = await page.title(); return { title };"
}

Using scriptBase64 Parameter (Complex Scripts)

For scripts with complex quotes, template literals, or special characters that would break JSON parsing:

Example 1: Complex String Handling

Original JavaScript:

const result = await page.evaluate(() => {
const elements = document.querySelectorAll('div[data-test="product"]');
return Array.from(elements).map(el => {
const name = el.querySelector('.name')?.textContent || "No name";
const price = el.querySelector('.price')?.textContent || "No price";
const description = el.querySelector('.desc')?.innerHTML.replace(/['"]/g, "'") || "";
return `Product: "${name}" - Price: ${price} - Desc: "${description}"`;
});
});
return result;

As Base64 request:

{
"url": "https://shop.example.com",
"scriptBase64": "Y29uc3QgcmVzdWx0ID0gYXdhaXQgcGFnZS5ldmFsdWF0ZSgoKSA9PiB7CiAgY29uc3QgZWxlbWVudHMgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yQWxsKCdkaXZbZGF0YS10ZXN0PSJwcm9kdWN0Il0nKTsKICByZXR1cm4gQXJyYXkuZnJvbShlbGVtZW50cykubWFwKGVsID0+IHsKICAgIGNvbnN0IG5hbWUgPSBlbC5xdWVyeVNlbGVjdG9yKCcubmFtZScpPy50ZXh0Q29udGVudC8vZ2l0LCAiJyIpIHx8ICIiOwogICAgY29uc3QgcHJpY2UgPSBlbC5xdWVyeVNlbGVjdG9yKCcuY29tcCcpPy50ZXh0Q29udGVudC8vZ2l0LCAiJyIpIHx8ICIiOwogICAgY29uc3QgZGVzY3JpcHRpb24gPSBlbC5xdWVyeVNlbGVjdG9yKCcuZGVzYycpPy5pbm5lckhUTUwucmVwbGFjZSgvWyciXS9nLCAiJyIpIHx8ICIiOwogICAgcmV0dXJuIGBQcm9kdWN0OiAiJHtuYW1lfSIgLSBQcmljZTogJHtwcmljZX0gLSBEZXNjOiAiJHtkZXNjcmlwdGlvbn0iYDsKICB9KTsKfSk7CnJldHVybiByZXN1bHQ7"
}

Example 2: Template Literals and Regex

Original JavaScript:

await page.waitForSelector('article');
const articles = await page.$$eval('article', articles => {
const regex = /[^\w\s]/gi;
return articles.map(article => {
const title = article.querySelector('h2')?.textContent?.replace(regex, '') || '';
const content = article.querySelector('.content')?.textContent || '';
const template = `
<div class="article">
<h3>${title}</h3>
<p>${content.substring(0, 100)}...</p>
</div>
`;
return { title, content: content.substring(0, 200), html: template };
});
});
return articles;

As Base64 request:

{
"url": "https://blog.example.com",
"scriptBase64": "YXdhaXQgcGFnZS53YWl0Rm9yU2VsZWN0b3IoJ2FydGljbGUnKTsKY29uc3QgYXJ0aWNsZXMgPSBhd2FpdCBwYWdlLiQkZXZhbCgnYXJ0aWNsZScsIGFydGljbGVzID0+IHsKICBjb25zdCByZWdleCA9IC9bXlx3XHNdL2dpOwogIHJldHVybiBhcnRpY2xlcy5tYXAoYXJ0aWNsZSA9PiB7CiAgICBjb25zdCB0aXRsZSA9IGFydGljbGUucXVlcnlTZWxlY3RvcignaDInKT8udGV4dENvbnRlbnQ/LnJlcGxhY2UocmVnZXgsICcnKSB8fCAnJzsKICAgIGNvbnN0IGNvbnRlbnQgPSBhcnRpY2xlLnF1ZXJ5U2VsZWN0b3IoJy5jb250ZW50Jyk/LnRleHRDb250ZW50IHx8ICcnOwogICAgY29uc3QgdGVtcGxhdGUgPSBgCiAgICAgIDxkaXYgY2xhc3M9ImFydGljbGUiPgogICAgICAgIDxoMz4ke3RpdGxlfTwvaDM+CiAgICAgICAgPHA+JHtjb250ZW50LnN1YnN0cmluZygwLCAxMDApfS4uLjwvcD4KICAgICAgPC9kaXY+CiAgICBgOwogICAgcmV0dXJuIHsgdGl0bGUsIGNvbnRlbnQ6IGNvbnRlbnQuc3Vic3RyaW5nKDAsIDIwMCksIGh0bWw6IHRlbXBsYXRlIH07CiAgfSk7Cn0pOwpyZXR1cm4gYXJ0aWNsZXM7"
}
Converting to Base64

You can use our Online Code Parser Tool to automatically convert your JavaScript code to Base64 format. Simply:

  1. Paste your JavaScript code
  2. Select "Base64" as the output format
  3. Copy the generated Base64 string
  4. Use it in the scriptBase64 parameter