how would I create a webscraping n8n that collects all data from a website and stores it in an airtable or google sheet, then the next day compare the prices
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Creating a web scraping workflow using n8n to collect data from a website, store it in Airtable or Google Sheets, and then compare prices the next day involves several steps. Below is a high-level overview of how you can achieve this:
Step 1: Set Up n8n
Install n8n: If you haven't already, install n8n on your server or use the n8n cloud service.
Create a New Workflow: In the n8n dashboard, create a new workflow.
Step 2: Web Scraping
Add a Web Scraping Node: Use the "HTTP Request" node to fetch the webpage content.
Method: GET
URL: The URL of the website you want to scrape.
Response Format: JSON or HTML (depending on the structure of the data).
Parse the Data: Use the "Function" node or "Set" node to extract the relevant data from the HTML or JSON response.
Example: If the data is in HTML, you might use a library like Cheerio to parse the HTML and extract the required information.
Step 3: Store Data in Airtable or Google Sheets
Add an Airtable or Google Sheets Node:
Airtable: Use the "Airtable" node to insert the scraped data into an Airtable base.
Operation: Create Record
Base ID: Your Airtable base ID
Table Name: The table where you want to store the data
Fields: Map the scraped data to the corresponding Airtable fields.
Google Sheets: Use the "Google Sheets" node to insert the scraped data into a Google Sheet.
Operation: Append Row
Spreadsheet ID: Your Google Sheet ID
Sheet Name: The sheet where you want to store the data
Fields: Map the scraped data to the corresponding Google Sheet columns.
Step 4: Schedule the Workflow
Set Up a Cron Node: Use the "Cron" node to schedule the workflow to run daily.
Cron Expression: Set the cron expression to run the workflow at the desired time (e.g., every day at midnight).
Step 5: Compare Prices
Add a Function Node: Use a "Function" node to compare the new data with the previous day's data.
Example: Fetch the previous day's data from Airtable or Google Sheets and compare it with the new data.
Logic: Implement the comparison logic in the function node (e.g., check if the price has increased, decreased, or remained the same).
Store Comparison Results: Use another Airtable or Google Sheets node to store the comparison results.
Operation: Create Record or Append Row
Fields: Map the comparison results to the corresponding fields.
Example Workflow
HTTP Request Node: Fetch the webpage content.
Function Node: Parse the HTML/JSON and extract the required data.
Airtable/Google Sheets Node: Store the scraped data.
Cron Node: Schedule the workflow to run daily.
Function Node: Compare the new data with the previous day's data.
Airtable/Google Sheets Node: Store the comparison results.
Example Code Snippet for Function Node (JavaScript)
javascript
// Example function to parse HTML and extract data
const cheerio = require('cheerio');
const html = items[0].json.body; // Assuming the HTML content is in the first item's JSON body
const $ = cheerio.load(html);
const data = [];
$('selector').each((index, element) => {
const item = {
name: $(element).find('name-selector').text(),
price: $(element).find('price-selector').text()
};
data.push(item);
});
return data;
Example Code Snippet for Comparison Function Node (JavaScript)
javascript
// Example function to compare prices
const previousData = await n8n.nodes.Airtable.execute({
operation: 'Get All Records',
baseId: 'your-base-id',
tableName: 'your-table-name'
});
const newData = items[0].json; // Assuming the new data is in the first item's JSON
const comparisonResults = newData.map(newItem => {
const previousItem = previousData.find(item => item.name === newItem.name);
return {
name: newItem.name,
previousPrice: previousItem ? previousItem.price : 'N/A',
newPrice: newItem.price,
priceChange: previousItem ? newItem.price - previousItem.price : 'N/A'
};
});
return comparisonResults;
Final Steps
Test the Workflow: Run the workflow manually to ensure it works as expected.
Deploy the Workflow: Save and deploy the workflow to run automatically based on the scheduled cron expression.
By following these steps, you should be able to create a web scraping workflow in n8n that collects data from a website, stores it in Airtable or Google Sheets, and compares prices daily.