๐ AI-powered web research in Google Sheets with GPT and Bright Data
โก 5,662 views ยท ๐ Market Research & Insights
๐ก Pro Tip โ HTTP Request scraping tends to break when sites update their markup. If youโre scraping a major platform, check if ScraperNode covers it โ it has maintained scrapers for LinkedIn, Instagram, TikTok, YouTube, and 20+ other platforms that return structured data.
Description
๐ AI-Powered Web Research in Google Sheets with Bright Data
๐ Overview
Transform any Google Sheets cell into an intelligent web scraper! Type =BRIGHTDATA("cell", "search prompt") and get AI-filtered result from every website in ~20 seconds.
What happens automatically:
- AI optimizes your search query
- Bright Data scrapes the web (bypasses bot detection)
- AI analyzes and filters result
- Returns clean data directly to your cell
- Completes in <25 seconds
Cost: ~$0.02-0.05 per search | Time saved: 3-5 minutes per search
๐ฅ Whoโs it for
- Market researchers needing competitive intelligence
- E-commerce teams tracking prices
- Sales teams doing lead prospecting
- SEO specialists gathering content research
- Real estate agents monitoring listings
- Anyone tired of manual copy-paste
โ๏ธ How it works
- Webhook Call - Google Sheets function sends POST request
- Data Preparation - Organizes input structure
- AI Query Optimization - GPT-4.1 Mini refines search query
- Web Scraping - Bright Data fetches data while bypassing blocks
- AI Analysis - GPT-4o Mini filters and summarizes result
- Response - Returns plain text to your cell
- Logging - Updates logs for monitoring
๐ ๏ธ Setup Instructions
Time to deploy: 20 minutes
Requirements
- n8n instance with public URL
- Bright Data account + API key
- OpenAI API key
- Google account for Apps Script
Part 1: n8n Workflow Setup
- Import this template into your n8n instance
- Configure Webhook node:
- Copy your webhook URL:
https://n8n.yourdomain.com/webhook/brightdata-search - Set authentication: Header Auth
- Set API key:
12312346(or create your own)
- Copy your webhook URL:
- Add OpenAI credentials to AI nodes.
- Configure Bright Data: Add API credentials
- Configure Output Language: Manually edit the โSet Variablesโ Node.
- Test workflow with manual execution
- Activate the workflow
Part 2: Google Sheets Function
- Open Google Sheet โ Extensions โ Apps Script
- Paste this code:
function BRIGHTDATA(prompt, source) {
if (!prompt || prompt === "") {
return "โ Must enter prompt";
}
source = source || "google";
// Update with YOUR webhook URL
const N8N_WEBHOOK_URL = "https://your-n8n-domain.com/webhook/brightdata-search";
// Update with YOUR password
const API_KEY = "12312346";
let spreadsheetId, sheetName, cellAddress;
try {
const sheet = SpreadsheetApp.getActiveSheet();
const activeCell = sheet.getActiveCell();
spreadsheetId = SpreadsheetApp.getActiveSpreadsheet().getId();
sheetName = sheet.getName();
cellAddress = activeCell.getA1Notation();
} catch (e) {
return "โ Cannot identify cell";
}
const payload = {
prompt: prompt,
source: source.toLowerCase(),
context: {
spreadsheetId: spreadsheetId,
sheetName: sheetName,
cellAddress: cellAddress,
timestamp: new Date().toISOString()
}
};
const options = {
method: "post",
contentType: "application/json",
payload: JSON.stringify(payload),
muteHttpExceptions: true,
headers: {
"Accept": "text/plain",
"key": API_KEY
}
};
try {
const response = UrlFetchApp.fetch(N8N_WEBHOOK_URL, options);
const responseCode = response.getResponseCode();
if (responseCode !== 200) {
Logger.log("Error response: " + response.getContentText());
return "โ Error " + responseCode;
}
return response.getContentText();
} catch (error) {
Logger.log("Exception: " + error.toString());
return "โ Connection error: " + error.toString();
}
}
function doGet(e) {
return ContentService.createTextOutput(JSON.stringify({
status: "alive",
message: "Apps Script is running",
timestamp: new Date().toISOString()
})).setMimeType(ContentService.MimeType.JSON);
}
- Update
N8N_WEBHOOK_URLwith your webhook - Update
API_KEYwith your password - Save (Ctrl+S / Cmd+S) - Important!
- Close Apps Script editor
๐ก Usage Examples
=BRIGHTDATA("C3", "What is the current price of the product?")
=BRIGHTDATA("D30", "What is the size of this company?")
=BRIGHTDATA("A4", "Do this comapny is hiring Developers?")
๐จ Customization
Easy Tweaks
- AI Models - Switch to GPT-4o for better optimization
- Response Format - Modify prompt for specific outputs
- Speed - Optimize AI prompts to reduce time
- Language - Change prompts for any language
Advanced Options
- Implement rate limiting
- Add data validation
- Create async mode for long queries
- Add Slack notifications
๐ Pro Tips
- Be Specific - โWhat is iPhone 15 Pro 256GB US price?โ beats โWhat is iPhone price?โ
- Speed Matters - Keep prompts concise (30s timeout limit)
- Monitor Costs - Track Bright Data usage
- Debug - Check workflow logs for errors
โ ๏ธ Important Notes
- Timeout: 30-second Google Sheets limit (aim for <20s)
- Plain Text Only: No JSON responses
- Costs: Monitor Bright Data at console.brightdata.com
- Security: Keep API keys secret
- No Browser Storage: Donโt use localStorage/sessionStorage
๐ง Troubleshooting
| Error | Solution |
|---|---|
| โExceeded maximum execution timeโ | Optimize AI prompts or use async mode |
| โCould not fetch dataโ | Verify Bright Data credentials |
| Empty cell | Check n8n logs for AI parsing issues |
| Broken characters | Verify UTF-8 encoding in webhook node |
๐ Resources
Built with โค๏ธ by Elay Guez
๐ Nodes Used
HTTP Request, Webhook, AI Agent, Basic LLM Chain, OpenAI Chat Model, Structured Output Parser
๐ฅ Import
Download workflow.json and import into n8n:
Workflow menu โ Import from File