Automated Web Data Extraction from Email Links to Google Sheets - n8n Workflow

Use this powerful n8n workflow to automatically extract links from Gmail, scrape data from the linked web page using HTML selectors, process the information, and save it to Google Sheets.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Data Analysts/Researchers: Users who regularly receive links via email containing structured data they need to log.
Operations Teams: Organizations needing to automate the processing of new case files or reports delivered via secure email links.
n8n Automation Specialists: Users looking for advanced examples of combining Gmail, HTTP Requests, HTML parsing, and custom Code nodes in a single n8n workflow.
Anyone needing automated web scraping initiated by a specific email n8n trigger.

Overview

Manually opening emails, clicking links, copying data points, and calculating derived values (like age or case type) is time-consuming and prone to human error. This advanced n8n workflow solves this problem by creating a fully automated pipeline. It starts by monitoring Gmail for relevant messages. Once found, an n8n node extracts the target URL embedded in the email body. The workflow then uses an HTTP Request to access that URL and a subsequent HTML n8n node to scrape key fields (e.g., patient name, case ID, date of birth, location) using CSS selectors.

A critical step is the custom processing performed in a Code n8n node, where the raw extracted data is cleaned, ages are calculated, and consultation types (e.g., 'TELEMEDICINA') are determined by analyzing the email subject line. Finally, the structured, processed data is seamlessly appended to a designated row in Google Sheets, providing a reliable and instantly updated database. This robust n8n template ensures efficiency and data integrity.

How it Works

This comprehensive n8n workflow executes the following steps:


  1. Manual Trigger: The n8n workflow is initiated manually (in a production environment, this would typically be replaced by a scheduled or real-time Gmail n8n trigger).

  2. Search Emails (Gmail n8n node): The workflow connects to Gmail to search for emails matching specific criteria, such as a designated sender email address and date range.

  3. Extract Link (HTML n8n node): For each matching email, an HTML n8n node parses the email body using a specific CSS selector (a[style*="color: #ffffff"]) to locate and extract the required data link (href).

  4. Access Web Page (HTTP Request n8n node): The n8n workflow uses the extracted link to make an HTTP request to the external webpage, retrieving its full HTML content.

  5. Capture Data (HTML n8n node): A second HTML n8n node analyzes the web page content and extracts critical patient/case details (like dtnasc, id, Nome, Queixa, etc.) using specialized CSS selectors (e.g., #lblMemberDateOfBirth).

  6. Process Information (Code n8n node): Custom JavaScript code standardizes dates, calculates the patient's age, cleans the Case ID, and cross-references the original email subject to classify the 'Tipo atendimento' (e.g., 'TELEMEDICINA' or 'PRESENCIAL'). This code n8n node transforms the raw data into ready-to-use variables.

  7. Set Variables (Set n8n node): A Set n8n node finalizes the data structure, mapping all processed values into clean variable names (Nome_Paciente, Idade, Tipo atendimento) for uniform output.

  8. Save to Sheets (Google Sheets n8n node): The final step appends the complete dataset (including date, time, age, type, case ID, and the original link) to the specified Google Sheets spreadsheet and tab.

Installation Guide

To install and use this n8n template, follow these steps:


  1. Import the n8n workflow: Copy the provided JSON data and paste it into your n8n instance via the 'New' > 'Import from JSON' option.

  2. Set Up Credentials: You will need to configure credentials for two services:

Gmail OAuth2: Connect your Gmail account so the 'Search Emails' n8n node can access your mailbox.
Google Sheets OAuth2 API: Connect your Google account with access to the target spreadsheet. Ensure the account has permission to read and write to the sheet.

  1. Configure Gmail Search: In the 'Search Emails' n8n node, update the sender and receivedAfter/receivedBefore filters to match the specific emails you wish to target.

  2. Configure HTML Selectors: Review the 'search for an element in the email body' and 'capture data' n8n nodes. If the structure of the emails or the target webpage changes, you must update the CSS selectors accordingly (e.g., #lblMemberDateOfBirth).

  3. Customize Code: The 'processes information' Code n8n node contains custom logic for date parsing, age calculation, and type classification. Adjust this JavaScript code if your data formats or classification rules differ.

  4. Configure Google Sheets: In the 'Save data in spreadsheet' n8n node, select the correct 'Document ID' and 'Sheet Name' where you want the final data saved. Ensure the column headers in the n8n node match your actual spreadsheet headers.

Node Details

When clicking ‘Test workflow’ (Manual Trigger n8n node): Serves as the starting point for testing this specific n8n workflow.
Search Emails (Gmail n8n node): Fetches emails based on complex criteria (sender and date range). Key Configuration: sender set to [email protected]; operation is getAll.
search for an element in the email body (HTML n8n node): Extracts the hidden URL link from the initial email content. Key Configuration: Uses CSS selector a[style="color: #ffffff"] to get the href attribute.
open the link (HTTP Request n8n node): Navigates to the extracted URL to fetch the full content of the target data page. Key Configuration: URL expression {{ $json.dados }}. Set to continue on error.
capture data (HTML n8n node): Scrapes specific fields from the accessed web page. Key Configuration: Extracts data using IDs like #lblMemberDateOfBirth (dtnasc), #txtCase (id), and others.
processes information (Code n8n node): Performs complex data manipulation. Key Function: Parses dates, calculates age, extracts clean case ID, and determines attendanceType by examining the emailSubject retrieved from the initial Search Emails n8n node.
set variables (Set n8n node): Restructures and renames output fields for clarity before saving. Key Configuration: Maps processed fields like caseId to id and combines Nome and sobrenome into Nome_Paciente.


  • Save data in spreadsheet (Google Sheets n8n node): Appends the final, structured data to the designated sheet. Key Configuration: operation is append; defines column mappings for headers like DATA, NOME, IDADE, and TIPO CONSULTA .

Related n8n Workflows

Free

Nodes: 8 Nodes
Updated: December 26 2025
View all
Created by
Renan Miller
Renan Miller

Featured*