Pull website data into Google Sheets with IMPORTXML
For a quick lookup, you may not need a scraper at all. Google Sheets has an IMPORTXML function that can pull public structured data from HTML, XML, RSS, and Atom feeds directly into cells.
It is useful for small, lightweight jobs. It is not a good fit for pages that require authentication, depend on client-side JavaScript, or actively block automated requests.
The two arguments
IMPORTXML(url, xpath_query)
url is the page to read, including the protocol. Put it in quotation marks or reference a cell that contains the URL.
xpath_query tells Sheets which parts of the document to return.
Finding an XPath
XPath is a query language for selecting elements and attributes in a structured document. You do not need to learn all of it before IMPORTXML becomes useful.
Chrome DevTools can give you a starting point. Inspect the element, right-click the highlighted node in the Elements panel, then choose Copy > Copy XPath. The generated path can be brittle, so simplify it when the page has stable elements or attributes you can target.
Some useful queries are:
//title— the page title//meta[@name='description']/@content— the meta description//@href— everyhrefvalue//a[contains(@href, 'example.com')]/@href— links containing a domain//a[not(contains(@href, 'example.com'))]/@href— links that do not contain a domain//link[@rel='canonical']/@href— the canonical URL//*[@itemtype]/@itemtype— schema item types//*[@hreflang]— elements with ahreflangattribute//meta[@name='robots']/@content— the robots directive
A small example
IMPORTXML("https://en.wikipedia.org/wiki/Moon_landing", "//a/@href")
IMPORTXML(A2,B2)
The first formula returns link targets from the page. The second keeps both arguments in cells, which is much easier to reuse across several rows.
Web pages change, and so do their XPath targets. For anything important or long-running, expect to maintain the sheet—or move the job to a proper API when one is available.