ScrapingAnt returns raw HTML that you must parse yourself, and costs $19/month for 100K credits at the Enthusiast tier. For common targets like Amazon, Google, and Reddit, a structured API returns parsed JSON directly, eliminating BeautifulSoup parsing code and reducing maintenance when page layouts change. This tutorial shows side-by-side migrations for the three most common ScrapingAnt use cases.
Prerequisites
- Python 3.8+
- requests library
- A Scavio API key from scavio.dev
- Existing ScrapingAnt integration to migrate
Walkthrough
Step 1: Compare the approaches side by side
See how ScrapingAnt raw HTML differs from structured API JSON.
import os, requests
from bs4 import BeautifulSoup
# --- ScrapingAnt approach (raw HTML) ---
# SA_KEY = os.environ.get('SCRAPINGANT_KEY', '')
# def scrape_google_sa(query):
# r = requests.get(f'https://api.scrapingant.com/v2/general',
# params={'url': f'https://www.google.com/search?q={query}', 'x-api-key': SA_KEY})
# soup = BeautifulSoup(r.text, 'html.parser')
# results = []
# for div in soup.select('div.g'):
# title = div.select_one('h3')
# link = div.select_one('a')
# if title and link:
# results.append({'title': title.text, 'link': link['href']})
# return results # Fragile: breaks when Google changes HTML
# --- Structured API approach (parsed JSON) ---
API_KEY = os.environ['SCAVIO_API_KEY']
SH = {'x-api-key': API_KEY, 'Content-Type': 'application/json'}
def search_google(query):
data = requests.post('https://api.scavio.dev/api/v1/search',
headers=SH, json={'query': query, 'country_code': 'us'}).json()
return data.get('organic_results', []) # Stable JSON, no parsing needed
results = search_google('best serp api 2026')
for r in results[:3]:
print(f'{r["position"]}. {r["title"][:50]} - {r["link"][:40]}')
print(f'\nNo HTML parsing. No BeautifulSoup. No CSS selectors.')Step 2: Migrate Amazon product searches
Replace ScrapingAnt Amazon scraping with structured product data.
# --- ScrapingAnt Amazon (before) ---
# def scrape_amazon_sa(query):
# r = requests.get('https://api.scrapingant.com/v2/general',
# params={'url': f'https://www.amazon.com/s?k={query}', 'x-api-key': SA_KEY})
# soup = BeautifulSoup(r.text, 'html.parser')
# products = []
# for item in soup.select('[data-component-type="s-search-result"]'):
# title = item.select_one('h2 span')
# price = item.select_one('.a-price .a-offscreen')
# # ... 20+ lines of fragile selector parsing
# return products
# --- Structured API (after) ---
def search_amazon(query):
data = requests.post('https://api.scavio.dev/api/v1/search',
headers=SH, json={'query': query, 'platform': 'amazon', 'country_code': 'us'}).json()
return data.get('organic_results', [])
products = search_amazon('wireless earbuds')
for p in products[:3]:
print(f'{p.get("title", "")[:50]} | {p.get("price", "N/A")} | {p.get("rating", "N/A")}')
print(f'\n3 lines vs 20+ lines of HTML parsing. Cost: $0.005/query.')Step 3: Migrate Reddit data extraction
Replace ScrapingAnt Reddit scraping with structured Reddit search.
# --- ScrapingAnt Reddit (before) ---
# def scrape_reddit_sa(query):
# r = requests.get('https://api.scrapingant.com/v2/general',
# params={'url': f'https://www.reddit.com/search/?q={query}', 'x-api-key': SA_KEY,
# 'browser': 'true'}) # Reddit needs JS rendering = more credits
# soup = BeautifulSoup(r.text, 'html.parser')
# # Reddit HTML changes frequently, selectors break monthly
# return posts
# --- Structured API (after) ---
def search_reddit(query):
data = requests.post('https://api.scavio.dev/api/v1/search',
headers=SH, json={'query': query, 'platform': 'reddit', 'country_code': 'us'}).json()
return data.get('organic_results', [])
posts = search_reddit('best api for web scraping')
for p in posts[:3]:
print(f'{p.get("title", "")[:60]}')
print(f' {p.get("snippet", "")[:80]}')
print(f'\nNo JS rendering needed. No browser credits. $0.005/query.')Step 4: Compare cost and maintenance
Calculate cost savings and reduced maintenance burden.
def cost_comparison(monthly_queries):
# ScrapingAnt: $19/mo for 100K credits
# Google search = 10 credits, Amazon = 10, Reddit w/ browser = 20
sa_google = monthly_queries * 10 / 100000 * 19
sa_amazon = monthly_queries * 10 / 100000 * 19
sa_reddit = monthly_queries * 20 / 100000 * 19 # JS rendering doubles credits
# Scavio: $0.005/query flat
sc_cost = monthly_queries * 0.005
print(f'Monthly cost comparison ({monthly_queries:,} queries/platform):')
print(f' ScrapingAnt Google: ${sa_google:.2f} (+ parsing maintenance)')
print(f' ScrapingAnt Amazon: ${sa_amazon:.2f} (+ parsing maintenance)')
print(f' ScrapingAnt Reddit: ${sa_reddit:.2f} (+ JS rendering cost)')
print(f' Scavio (all three): ${sc_cost * 3:.2f} (structured JSON, no parsing)')
print(f'\nLines of parsing code eliminated: ~60-100 (BeautifulSoup selectors)')
print(f'Maintenance: 0 selector updates vs monthly fixes when layouts change')
cost_comparison(1000)
cost_comparison(5000)Python Example
import os, requests
SH = {'x-api-key': os.environ['SCAVIO_API_KEY'], 'Content-Type': 'application/json'}
# Replace ScrapingAnt for Google, Amazon, Reddit in 3 lines each:
def search(query, platform=None):
body = {'query': query, 'country_code': 'us'}
if platform: body['platform'] = platform
data = requests.post('https://api.scavio.dev/api/v1/search', headers=SH, json=body).json()
return data.get('organic_results', [])
for p in [None, 'amazon', 'reddit']:
results = search('wireless earbuds', p)
print(f'{p or "google"}: {len(results)} results ($0.005, no HTML parsing)')JavaScript Example
const SH = { 'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json' };
async function search(query, platform) {
const body = { query, country_code: 'us' };
if (platform) body.platform = platform;
const data = await fetch('https://api.scavio.dev/api/v1/search', {
method: 'POST', headers: SH, body: JSON.stringify(body)
}).then(r => r.json());
return data.organic_results || [];
}
for (const p of [null, 'amazon', 'reddit']) {
const results = await search('wireless earbuds', p);
console.log(`${p || 'google'}: ${results.length} results ($0.005, no parsing)`);
}Expected Output
1. Scavio - Search API for Developers - https://scavio.dev
2. SerpAPI - Google Search API - https://serpapi.com
3. DataForSEO - SEO Data API - https://dataforseo.com
No HTML parsing. No BeautifulSoup. No CSS selectors.
Monthly cost comparison (1,000 queries/platform):
ScrapingAnt Google: $1.90 (+ parsing maintenance)
ScrapingAnt Amazon: $1.90 (+ parsing maintenance)
ScrapingAnt Reddit: $3.80 (+ JS rendering cost)
Scavio (all three): $15.00 (structured JSON, no parsing)
Lines of parsing code eliminated: ~60-100