Maggie Moore
Maggie Moore

Reputation: 19

Web Scraping Google Sheets Script

I'm trying to input data based on column "A" into column "B". If "A" is a comprehensive list of website urls, would it be possible to run a script that scrapes the phone numbers, for example, from these websites and inputs into column "B"?

I am 100% newbie to scripting, but would love to learn how this works.

Upvotes: 1

Views: 175

Answers (1)

Yaakov Bressler
Yaakov Bressler

Reputation: 12018

Assuming each cell in Column A is one url, you definitely can scrape for phone numbers.

enter image description here

The code to achieve this:

  • Extract the webpage's text (assuming the phone number isn't structured as a link or something else).
  • Search that text for phone numbers using regex.
B2: =JOIN("|",IMPORTXML(A2,"//a/@href"))
C2: =REGEXEXTRACT(B2,"[0-9]{3}[- ]*[0-9]{3}[- ]*[0-9]{4}")

Upvotes: 2

Related Questions