I am trying to use google apps script's UrlFetchApp service to scrape top 5 google search results.
let response=UrlFetchApp.fetch("https://www.google.com/search?q="+encodeURIComponent("how to eat pizza" ),
{ "User-Agent": "Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36",
"method" : "GET",
}
).getContentText();
It was supposed to give similar results as searching through the browser.
I was expecting <div class="r">
(which will have href, title) in the response but don't see them.
When I send request using python's requests.get(URL, headers=headers)
I was getting those tags <div class="r">
as expected.
I am unable to figure out the cause of the difference. Google custom search API is different I believe. urlfetchapp is supposed to give response for a simple get request.