I had written this original article on my website aozata.com . Wanted to share this method with the dev community here at Dev.to.
Here are steps to scrape google search results in google sheets. It only gets 10 results per search query.
- Create a google sheet in your google drive.
- Create a google custom search engine.
- Enable search the entire web.
- Copy your google custom search engine id.
- Get your google custom search api key from here
- Formulate your api key in this format.
key is your API key,
cx is your google custom search id.
In your google sheets, go to tools-> script editor-> paste the following code->save the file as ImportJSON.gs. The ImportJSON.gs can be downloaded from here https://www.aozata.com/importjson-gs/
Enter the cx, key, search query (q), API URL in different cells.
Use the concatenate function to join all these 4 variables to get your final API URL. For example
=concatenate(D4,D2,"&cx=",D1,"&q=",D3)
- Use the ImportJSON function to import the google search results. for example to get the title of the search results
=ImportJSON($D$5,"/items/title","noHeaders")
You can buy this google sheet from here.
Top comments (0)