Can I combine n8n with WebScraping.AI for better results?
Yes, combining n8n with WebScraping.AI significantly improves your web scraping workflows by providing enterprise-grade scraping capabilities without the complexity of managing browsers, proxies, and anti-bot detection systems. WebScraping.AI offers a robust API specifically designed for integration with automation platforms like n8n, delivering reliable data extraction with built-in proxy rotation, CAPTCHA solving, and JavaScript rendering.
Why Combine n8n with WebScraping.AI?
Advantages Over Self-Managed Scraping
1. No Infrastructure Management - No need to maintain Puppeteer or Playwright instances - No proxy server setup or rotation logic - No CAPTCHA solving implementation - Automatic scaling without server provisioning
2. Built-in Anti-Bot Protection - Residential and datacenter proxy pools - Automatic retry logic - Smart rate limiting - Browser fingerprint rotation
3. AI-Powered Data Extraction - Question-answering capabilities - Structured field extraction - Natural language queries - No need to write complex CSS or XPath selectors
4. Simplified Workflow Logic - Single HTTP request replaces multiple nodes - Reduced error handling complexity - Lower workflow execution time - Better maintainability
Setting Up WebScraping.AI in n8n
Prerequisites
- Sign up for a WebScraping.AI account at webscraping.ai
- Obtain your API key from the dashboard
- Have n8n installed (self-hosted or cloud version)
Basic Integration with HTTP Request Node
Here's how to integrate WebScraping.AI into your n8n workflow using the HTTP Request node:
Step 1: Add HTTP Request Node
In your n8n workflow, add an HTTP Request node with the following configuration:
{
"method": "GET",
"url": "https://api.webscraping.ai/html",
"authentication": "genericCredentialType",
"genericAuthType": "queryAuth",
"queryParameters": {
"api_key": "YOUR_API_KEY",
"url": "https://example.com",
"js": "true",
"proxy": "residential"
}
}
Step 2: Configure Credentials
Create a new credential for WebScraping.AI:
- Credential Type: Query Auth
- Name: api_key
- Value: Your WebScraping.AI API key
Scraping HTML Content
To scrape the full HTML of a page with JavaScript rendering:
// n8n HTTP Request node configuration
{
"method": "GET",
"url": "https://api.webscraping.ai/html",
"qs": {
"api_key": "{{$credentials.webScrapingAI}}",
"url": "{{$node['Previous Node'].json['target_url']}}",
"js": true,
"timeout": 10000,
"proxy": "residential"
}
}
Then use the HTML node to parse the response:
// n8n Code node (JavaScript)
const html = items[0].json.body;
const cheerio = require('cheerio');
const $ = cheerio.load(html);
// Extract data
const title = $('h1').text();
const price = $('.price').text();
const description = $('.description').text();
return [{
json: {
title,
price,
description
}
}];
Using AI-Powered Question Extraction
One of WebScraping.AI's most powerful features is the ability to extract data using natural language questions:
// n8n HTTP Request node for AI question answering
{
"method": "GET",
"url": "https://api.webscraping.ai/question",
"qs": {
"api_key": "{{$credentials.webScrapingAI}}",
"url": "{{$json['product_url']}}",
"question": "What is the product price and availability?",
"js": true,
"proxy": "residential"
}
}
This eliminates the need for complex HTML parsing - just ask questions in plain English and get structured answers.
Extracting Structured Fields
For extracting multiple fields at once, use the fields endpoint:
// n8n HTTP Request node for field extraction
{
"method": "POST",
"url": "https://api.webscraping.ai/fields",
"headers": {
"Content-Type": "application/json"
},
"body": {
"api_key": "{{$credentials.webScrapingAI}}",
"url": "{{$json['url']}}",
"fields": {
"title": "Product title",
"price": "Current price in USD",
"rating": "Average customer rating",
"reviews_count": "Total number of reviews",
"in_stock": "Is the product available?"
},
"js": true,
"proxy": "residential"
}
}
Real-World n8n + WebScraping.AI Workflows
Example 1: E-commerce Price Monitoring
This workflow monitors competitor prices and sends alerts:
// Workflow structure:
// 1. Schedule Trigger (daily at 9 AM)
// 2. HTTP Request (WebScraping.AI fields endpoint)
// 3. Code Node (process and compare prices)
// 4. IF Node (check if price changed)
// 5. Send Email (alert on price changes)
// HTTP Request node body:
{
"api_key": "{{$credentials.webScrapingAI}}",
"url": "{{$json['competitor_url']}}",
"fields": {
"product_name": "Name of the product",
"current_price": "Current price",
"original_price": "Original or list price",
"discount": "Discount percentage if any",
"availability": "In stock or out of stock"
},
"js": true,
"proxy": "residential",
"country": "us"
}
// Code node to process results:
const newPrice = parseFloat($json['current_price'].replace(/[^0-9.]/g, ''));
const oldPrice = $node['Database'].json['last_price'];
if (newPrice !== oldPrice) {
return [{
json: {
product: $json['product_name'],
old_price: oldPrice,
new_price: newPrice,
change_percent: ((newPrice - oldPrice) / oldPrice * 100).toFixed(2),
timestamp: new Date().toISOString()
}
}];
}
return [];
Example 2: Lead Generation from Directory Sites
Scrape business listings and enrich lead data:
// Workflow structure:
// 1. Webhook Trigger (receives category URLs)
// 2. HTTP Request (get page HTML)
// 3. Code Node (extract listing URLs)
// 4. Split In Batches (process 10 at a time)
// 5. HTTP Request (WebScraping.AI question endpoint)
// 6. Google Sheets (save leads)
// First HTTP Request (get directory page):
{
"method": "GET",
"url": "https://api.webscraping.ai/html",
"qs": {
"api_key": "{{$credentials.webScrapingAI}}",
"url": "{{$json['directory_url']}}",
"js": true,
"proxy": "residential"
}
}
// Second HTTP Request (extract business details):
{
"method": "POST",
"url": "https://api.webscraping.ai/fields",
"body": {
"api_key": "{{$credentials.webScrapingAI}}",
"url": "{{$json['business_url']}}",
"fields": {
"business_name": "Company or business name",
"phone": "Contact phone number",
"email": "Contact email address",
"address": "Full physical address",
"website": "Website URL",
"description": "Brief description of services"
},
"js": true,
"proxy": "residential"
}
}
Example 3: Content Aggregation for SEO
Aggregate content from multiple sources for analysis:
// Workflow structure:
// 1. Schedule Trigger (weekly)
// 2. Code Node (list of competitor URLs)
// 3. Split In Batches
// 4. HTTP Request (WebScraping.AI selected endpoint)
// 5. Code Node (analyze content)
// 6. Airtable (store results)
// HTTP Request for selected content:
{
"method": "GET",
"url": "https://api.webscraping.ai/selected",
"qs": {
"api_key": "{{$credentials.webScrapingAI}}",
"url": "{{$json['article_url']}}",
"selector": "article, .post-content, .entry-content",
"js": true,
"proxy": "residential"
}
}
// Code node for content analysis:
const content = $json['selected_html'];
const cheerio = require('cheerio');
const $ = cheerio.load(content);
// Extract text and analyze
const text = $('*').text();
const wordCount = text.split(/\s+/).length;
const headings = $('h2, h3').map((i, el) => $(el).text()).get();
const images = $('img').length;
const links = $('a[href^="http"]').length;
return [{
json: {
url: $json['article_url'],
word_count: wordCount,
headings: headings,
image_count: images,
external_links: links,
scraped_at: new Date().toISOString()
}
}];
Handling Pagination in n8n with WebScraping.AI
For scraping multiple pages, combine n8n's loop functionality with WebScraping.AI:
// Initial Code node to generate page URLs:
const baseUrl = "https://example.com/products?page=";
const totalPages = 10;
const urls = [];
for (let i = 1; i <= totalPages; i++) {
urls.push({ url: baseUrl + i });
}
return urls.map(item => ({ json: item }));
// HTTP Request node in loop:
{
"method": "GET",
"url": "https://api.webscraping.ai/html",
"qs": {
"api_key": "{{$credentials.webScrapingAI}}",
"url": "{{$json['url']}}",
"js": true,
"proxy": "residential",
"timeout": 15000
}
}
Error Handling and Retry Logic
WebScraping.AI provides detailed error information. Here's how to handle errors in n8n:
// Error handler Code node:
const errorData = $json;
// Check for rate limit
if (errorData.statusCode === 429) {
// Wait and retry
return [{
json: {
action: 'wait',
seconds: 60,
retry: true
}
}];
}
// Check for temporary failures
if (errorData.statusCode >= 500) {
return [{
json: {
action: 'retry',
max_attempts: 3,
backoff: 'exponential'
}
}];
}
// Log permanent failures
return [{
json: {
action: 'log',
error: errorData.error,
url: errorData.url,
timestamp: new Date().toISOString()
}
}];
Performance Optimization Tips
1. Use Appropriate Proxy Types - Datacenter proxies for non-restrictive sites (faster, cheaper) - Residential proxies for bot-protected sites (slower, more reliable)
2. Batch Processing - Use Split In Batches node to process 5-10 URLs at a time - Prevents rate limiting and improves success rate
3. Caching Strategy - Store scraped data in n8n's built-in cache - Set appropriate cache TTL based on content update frequency
4. Selective JavaScript Rendering
- Set js=false
for static pages to reduce costs and latency
- Only enable JavaScript when handling AJAX requests is necessary
5. Smart Timeouts - Use lower timeouts (5000ms) for simple pages - Increase timeout (20000ms) for complex SPAs
Cost Optimization
WebScraping.AI charges per API call. Optimize costs by:
- Using the right endpoint: HTML endpoint is cheaper than AI-powered endpoints
- Disabling JavaScript when possible: Saves 2x credits per request
- Implementing smart caching: Store results in n8n or external database
- Selective proxy usage: Use datacenter proxies when residential aren't required
Python Alternative for Advanced Use Cases
While n8n provides a no-code solution, you can also use Python with WebScraping.AI:
import requests
import json
def scrape_with_webscraping_ai(url, fields):
"""Scrape structured data using WebScraping.AI"""
api_endpoint = "https://api.webscraping.ai/fields"
payload = {
"api_key": "YOUR_API_KEY",
"url": url,
"fields": fields,
"js": True,
"proxy": "residential"
}
response = requests.post(api_endpoint, json=payload)
response.raise_for_status()
return response.json()
# Example usage
fields = {
"title": "Page title or heading",
"price": "Product price",
"rating": "User rating"
}
result = scrape_with_webscraping_ai(
"https://example.com/product",
fields
)
print(json.dumps(result, indent=2))
Comparison: Native n8n Scraping vs WebScraping.AI
| Feature | Native n8n (Puppeteer) | With WebScraping.AI | |---------|----------------------|-------------------| | Setup Complexity | High (requires browser config) | Low (API key only) | | Proxy Management | Manual implementation | Built-in rotation | | CAPTCHA Handling | Requires third-party service | Included | | JavaScript Rendering | Yes (resource intensive) | Yes (optimized) | | Rate Limiting | Manual implementation | Automatic | | Error Handling | Complex | Simplified | | Scaling | Limited by server resources | Automatic | | Cost | Infrastructure + maintenance | Per-request pricing | | Reliability | Depends on setup | Enterprise-grade SLA |
Troubleshooting Common Issues
Issue: Timeout errors on slow-loading pages
// Solution: Increase timeout
{
"api_key": "YOUR_API_KEY",
"url": "https://slow-website.com",
"timeout": 30000, // 30 seconds
"js": true
}
Issue: Blocked by anti-bot protection
// Solution: Use residential proxies and longer waits
{
"api_key": "YOUR_API_KEY",
"url": "https://protected-site.com",
"proxy": "residential",
"wait_for": "networkidle", // Wait for all network requests
"js": true
}
Issue: Rate limiting in n8n workflows
// Solution: Add delay between requests
// Use Function node with delay:
await new Promise(resolve => setTimeout(resolve, 2000));
return items;
Conclusion
Combining n8n with WebScraping.AI creates a powerful, scalable web scraping solution that eliminates the complexity of managing infrastructure while providing enterprise-grade reliability. The integration is straightforward using n8n's HTTP Request node, and the AI-powered extraction capabilities significantly reduce the need for complex parsing logic.
Whether you're building price monitoring workflows, lead generation systems, or content aggregation pipelines, this combination offers the best of both worlds: n8n's flexible automation capabilities and WebScraping.AI's robust scraping infrastructure.
For developers who need to handle authentication in their scraping workflows or monitor network requests for debugging, WebScraping.AI handles these complexities automatically, allowing you to focus on data extraction and business logic rather than infrastructure management.