Vision-Based AI Agent Scraper - with Google Sheets, ScrapingBee, and Gemini n8n Workflow Template

n8n workflow template · 14 nodes · Google Gemini

Vision-Based AI Agent Scraper - with Google Sheets, ScrapingBee, and Gemini is a free n8n workflow template that runs when another workflow calls it and works with Google Gemini and Google Sheets. It has 14 nodes, 4 of them AI nodes (Structured Output Parser, Google Gemini Chat Model, Call n8n Workflow Tool and AI Agent). The notes inside the workflow say: “This node uses ScrapingBee, a powerful scraping tool, to capture a screenshot of the desired URL. You can try ScrapingBee and enjoy 1,000 free requests (non-affiliate link).” To run it, you add your own credentials for Google Gemini (PaLM) API and Google Service Account.

At a glance

Trigger
Execute Workflow Trigger (HTML-Scraping Tool)
Nodes
14
Apps
Google Gemini and Google Sheets
AI nodes
4
Credentials
2 types
Category
Spreadsheets, databases and docs

Apps and integrations

  • Google Gemini
  • Google Sheets

Node types used

  • Manual Trigger
  • HTTP Request
  • Structured Output Parser
  • Google Gemini Chat Model
  • Split Out
  • Google Sheets
  • Edit Fields (Set)
  • Call n8n Workflow Tool
  • AI Agent
  • Execute Workflow Trigger
  • Markdown

How it works

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

ScrapingBee - Get Page Screenshot

This node uses ScrapingBee, a powerful scraping tool, to capture a screenshot of the desired URL. You can try ScrapingBee and enjoy 1,000 free requests (non-affiliate link).

Ensure the screenshot_full_page parameter is set to true for a full-page screenshot. This is crucial for vision-based scraping with the AI Agent.

Alternatively, you can choose to screenshot only a specific part of the page. However, keep in mind that the AI Agent will extract data only from the visible section—it has vision, but not a crystal ball!

HTML-Scraping Tool Trigger

This node serves as the entry point for the HTML scraping tool.

It is triggered by the AI Agent only when it fails to extract data from the screenshot. The URL is sent as a parameter for the query.

Vision-Based Scraping AI Agent

This is the central node of the workflow, powered by an AI Agent with two key prompts

  • System Prompt: Instructs the AI on how and what data to extract from the screenshot. You can customize this to suit your needs. It also includes fallback instructions to call a tool for retrieving the HTML page if data extraction from the screenshot fails.
  • User Message: Provides the page URL for context.

Sub-Nodes

  1. Google Gemini Chat Model

Chosen because tests show that Gemini-1.5-Pro outperforms GPT-4 and GPT-4-Vision in visual tasks. Either my prompt wasn’t optimized for GPT models, or GPT might need glasses. Other multimodal LLMs haven’t been tested yet.

  1. HTML-Based Scraping Tool

A fallback tool the agent uses if it cannot extract data directly from the screenshot.

  1. Structured Output Parser

Formats the extracted data into an easy-to-use structure, ready to be added to the results page in Google Sheets.

Google Gemini Chat Model

The default model is gemini-1.5-pro. It offers excellent performance for this use case, but it’s not the most cost-effective option—use it judiciously.

HTML-Based Scraping Tool

This tool is invoked when the AI Agent requires the HTML (converted to Markdown) to extract data because the screenshot alone wasn’t sufficient.

ScrapingBee - Get Page HTML

This node utilizes the ScrapingBee API to retrieve the HTML of the webpage.

Structured Output Parser

This node organizes the extracted data into an easy-to-use JSON format.

In this template, the JSON is designed for an e-commerce webpage. Customize it to fit your specific needs.

HTML to Markdown

This node converts the HTML from the previous node into Markdown format, helping to save tokens.

The converted Markdown is then automatically sent to the AI Agent through this node.

Split Out

This node splits the array created by the Structured Output Parser into individual rows, making them easy to append to the subsequent Google Sheets node.

Google Sheets - Create Rows

This node creates rows in the Results sheet using the extracted data.

You can use the example Google Sheet as a template. However, ensure that the columns in the Results sheet are aligned with the structure of the output from the Structured Output Parser node.

Setup notes

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Vision-Based AI Agent Scraper - with Google Sheets, ScrapingBee, and Gemini

Important notes

Check legal regulations

This workflow involves scraping, so make sure to check the legal regulations around scraping in your country before getting started. Better safe than sorry!

Workflow description

This workflow leverages a vision-based AI Agent, integrated with Google Sheets, ScrapingBee, and the Gemini-1.5-Pro model, to extract structured data from webpages. The AI Agent primarily uses screenshots for data extraction but switches to HTML scraping when necessary, ensuring high accuracy.

Key features include

  • Google Sheets Integration: Manage URLs to scrape and store structured results.
  • ScrapingBee: Capture full-page screenshots and retrieve HTML data for fallback extraction.
  • AI-Powered Data Parsing: Use Gemini-1.5-Pro for vision-based scraping and a Structured Output Parser to format extracted data into JSON.
  • Token Efficiency: HTML is converted to Markdown to optimize processing costs.

This template is designed for e-commerce scraping but can be customized for various use cases.

Trigger

The default trigger is When clicking ‘Test workflow’, meaning the workflow will need to be triggered manually.

You can replace this by selecting a trigger of your choice.

Google Sheets - List of URLs

The Google Sheet will contain two sheets

  • List of URLs to scrape
  • Results page, populated with the scraping results and AI-extracted data.

Here is an example Google Sheet you can use. The "Results" sheet is pre-configured for e-commerce website scraping. You can adapt it to your specific needs, but remember to adjust the Structured Output Parser node accordingly.

Set Fields

This node allows you to define the fields that will be sent to the ScrapingBee HTTP Node and the AI Agent.

In this template, only one field is pre-configured: url. You can customize it by adding additional fields as needed.

Set Fields - From AI Agent Query

This node sets the fields from the AI Agent’s query.

In this template, the only field configured is url.

Nodes in this workflow

The 14 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:

  1. When clicking ‘Test workflow’ (Manual Trigger)
  2. ScrapingBee- Get page HTML (HTTP Request)
  3. Structured Output Parser (Structured Output Parser)
  4. Google Gemini Chat Model (Google Gemini Chat Model)
  5. Split Out (Split Out)
  6. Google Sheets - Get list of URLs (Google Sheets)
  7. Set fields (Edit Fields (Set))
  8. ScrapingBee - Get page screenshot (HTTP Request)
  9. HTML-based Scraping Tool (Call n8n Workflow Tool)
  10. Google Sheets - Create Rows (Google Sheets)
  11. Vision-based Scraping Agent (AI Agent)
  12. HTML-Scraping Tool (Execute Workflow Trigger)
  13. Set fields - from AI agent query (Edit Fields (Set))
  14. HTML to Markdown (Markdown)

Credentials you need

  • Google Gemini (PaLM) API – used by Google Gemini Chat Model
  • Google Service Account – used by Google Sheets - Create Rows and Google Sheets - Get list of URLs

Configure your own credentials after importing. Create each credential in n8n, then select it in the node.

How to import into n8n

  1. Download the JSON file with the button above.
  2. In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
  3. Open each node that shows a warning and select or create its credential.
  4. Read the notes on the canvas, test the workflow with sample data, then activate it.

Do you need somewhere to run it? Read our guide to self-hosted n8n.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us