Use this powerful n8n workflow to scrape complex web pages, clean HTML, and use Google Gemini to generate custom Cheerio.js extraction code for structured JSON output. Deploy this advanced n8n automation today.
Download this n8n workflow template and start using it instantly.
This advanced n8n workflow solves the common problem of creating and maintaining brittle web scraper scripts. Instead of manually inspecting element selectors and writing complex Cheerio or Puppeteer code, this automation leverages the power of Google Gemini. The n8n node sequence first scrapes the target page, then cleans the raw HTML. This cleaned HTML is fed into the LLM, which is prompted to generate the precise JavaScript function needed to extract specific data fields (like titles, URLs, and scores).
This method makes the n8n workflow highly adaptable. If the target site's layout changes slightly, the AI can often generate updated extraction code on the fly. This sophisticated n8n template demonstrates how to execute dynamic, AI-generated code safely within a secure environment, providing structured JSON output from any webpage. It’s an essential tool for any serious n8n user engaging in web data tasks.
This n8n workflow operates in five distinct stages, beginning with a simple n8n trigger:
Generate custom web scraper manual n8n trigger, initiating the data flow.ScrapeNinja n8n node accesses the target URL (configured here as https://news.ycombinator.com/) and fetches the raw HTML content.Cleanup HTML n8n node takes the raw output and uses the dedicated cleanup-html operation to standardize and simplify the code, making it easier for the AI to analyze.Generate JS eval code via LLM n8n node, which is powered by the connected Google Gemini Chat Model. A specific prompt instructs the AI to generate a complete Cheerio.js function designed to extract news items and return them in a structured JSON array format. The prompt strictly requires the response to start with function extract(html, cheerioInstance) { ... }.Eval generated code to extract data n8n node executes the extraction function received from the LLM against the original cleaned HTML. This performs the extract-custom operation, resulting in a structured, actionable JSON data set, completing this powerful n8n workflow.To deploy this powerful n8n workflow template, follow these steps:
ScrapeNinja n8n node parameters to reflect the specific URL you wish to scrape.Generate custom web scraper n8n trigger to test the entire flow and verify that the Eval generated code to extract data n8n node successfully outputs the structured JSON data.This n8n workflow uses several critical n8n node types to achieve its goal:
Generate custom web scraper (Manual Trigger): The starting n8n trigger point for manual execution.
ScrapeNinja (Initial Scrape): Function: Fetches the raw HTML content from the specified URL (https://news.ycombinator.com/).
Cleanup HTML (ScrapeNinja): Function: Cleans and simplifies the raw HTML using the cleanup-html operation, preparing it for LLM analysis.
Google Gemini Chat Model (Language Model): Function: Provides the AI engine (models/gemini-exp-1206) necessary for generating dynamic JavaScript code.
Generate JS eval code via LLM (Chain LLM): Function: Sends the cleaned HTML and a highly specific prompt to the Gemini LLM. It dictates that the AI must return a runnable cheerio.js function for parsing the news items. This is a crucial n8n node for the workflow's adaptability.
Eval generated code to extract data (ScrapeNinja): Function: Executes the AI-generated JavaScript function against the cleaned HTML content using the extract-custom operation. This final n8n node yields the desired structured JSON output.
Scrape websites and run advanced custom analysis prompts using this powerful n8n workflow. Integrate Apify scraping data with Gemini via OpenRouter to get structured results.

Use this powerful n8n workflow to scrape Amazon product details via Decodo, leverage OpenAI for competitive analysis and structured insights, and automatically log the findings to Google Sheets.

Use this n8n workflow to scrape Yelp business data automatically via a web form using the Scrape.do API, parse the resulting HTML, and save all structured data directly to a Google Sheet.

Use this powerful n8n workflow template to automatically scrape business emails from Google Maps search results based on custom queries and save them directly to Google Sheets.

Automate seamless web scraping using this powerful n8n workflow template. Bypass anti-bot systems with Scrappey, starting from an n8n trigger and handling test data input.

I am a software engineer and technical lead with over 15 years of experience, and I am passionate about building and scaling SaaS products. ScrapeNinja.net (bootstrapped) has been the most exciting and challenging product I have built so far. ScrapeNinja is primarily aimed at fellow developers and founders of software products, and it tries to alleviate the major pains of reliable, observable and scalable web scraping and feeding data into LLMs.







































