DEV Community

Алексей Спинов
Алексей Спинов

Posted on

Automate Data Entry: From Web Pages to Spreadsheets (No-Code + Code)

Data entry from web pages to spreadsheets is tedious. Here is how to automate it.

No-Code Option: Google Sheets IMPORTXML

=IMPORTXML("https://example.com", "//h1")
=IMPORTXML("https://example.com", "//table//tr//td")
Enter fullscreen mode Exit fullscreen mode

Works for simple pages. Breaks on JavaScript-heavy sites.

Code Option: Scrape to Google Sheets

const { google } = require("googleapis");
const cheerio = require("cheerio");

// 1. Scrape the data
const res = await fetch(url);
const $ = cheerio.load(await res.text());
const rows = $("table tr").map((i, row) =>
  $(row).find("td").map((j, cell) => $(cell).text().trim()).get()
).get();

// 2. Write to Google Sheets
const sheets = google.sheets({ version: "v4", auth });
await sheets.spreadsheets.values.append({
  spreadsheetId: "YOUR_SHEET_ID",
  range: "Sheet1",
  valueInputOption: "RAW",
  requestBody: { values: rows }
});
Enter fullscreen mode Exit fullscreen mode

Code Option: Scrape to Excel

const XLSX = require("xlsx");
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.aoa_to_sheet([headers, ...rows]);
XLSX.utils.book_append_sheet(wb, ws, "Data");
XLSX.writeFile(wb, "output.xlsx");
Enter fullscreen mode Exit fullscreen mode

Common Use Cases

  • PDF invoices to Excel
  • Web directory to spreadsheet
  • Product catalogs to CSV
  • Job listings to Google Sheets
  • Contact pages to CRM

Resources


Need web data in your spreadsheet? $20. Any website to Excel/CSV/Google Sheets. Email: Spinov001@gmail.com | Hire me

Top comments (0)