Prompt
How do I scrape directories into Google Sheets?
Latest observation
Jul 15, 2026 · OpenAI APIWeb search: off
If by “scrape directories” you mean pull directory listing data from websites into Google Sheets, you have a few common options depending on the site:
1) Use IMPORTHTML for simple directory pages
If the directory is in an HTML table or list, try:
=IMPORTHTML("https://example.com/directory","table",1)
or
=IMPORTHTML("https://example.com/directory","list",1)
This works only when the page is publicly accessible and the data is in a clean HTML table/list.
2) Use IMPORTXML for structured page content
If the site has readable HTML elements, you can extract specific fields with XPath:
=IMPORTXML("https://example.com/directory","//h2")
Example for links:
=IMPORTXML("https://example.com/directory","//a/@href")
This is useful for directories with repeated card-style entries.
3) Use Google Apps Script for custom scraping
For more control, use Apps Script in Google Sheets:
- Open your Sheet
- Go to Extensions → Apps Script
- Write a script using
UrlFetchApp.fetch() - Parse the HTML and write results to the sheet
Example:
function scrapeDirectory() {
const url = "https://example.com/directory";
const html = UrlFetchApp.fetch(url).getContentText();
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
// Simple example: extract all links
const matches = [...html.matchAll(/<a[^>]*href="([^"]*)"[^>]*>(.*?)<\/a>/gi)];
const rows = matches.map(m => [m[2].replace(/<[^>]+>/g, ''), m[1]]);
sheet.getRange(1,1,rows.length,2).setValues(rows);
}
This is better if:
- the site needs pagination
- you need to log in
- the page is messy
- you want custom field extraction
4) Use an external scraper + export to CSV
If the site blocks scraping or is heavily dynamic (JavaScript-rendered), use:
- Python + BeautifulSoup / Scrapy / Selenium
- a no-code scraper like Apify, Browse AI, Octoparse
Then export the data to CSV and import into Google Sheets.
Important notes
- Make sure scraping is allowed by the site’s terms of service
- Check
robots.txt - Avoid scraping personal data without a lawful basis
- Public directories are often rate-limited or blocked if requests are too frequent
If you want, I can help you with one of these specifically:
- A Google Sheets formula
- An Apps Script scraper
- A Python scraper that exports to Sheets
- Scraping a specific directory site if you share the URL