My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Is it poosible to write a script to get Google search results XHR response or XHR URL?

Hashir Tariq's photo
Hashir Tariq
·Feb 18, 2017

I want to extract the data given by google itself like in the image given below. http://i.imgur.com/cxqNtWP.jpg The data I want to get is the one in the Red box. The data is present in the XHR response which i have underlined. Now is it poosible to write a script to obtain this data or even the URL? So far I have tried this :

 var xhr = new XMLHttpRequest();
xhr.responseType = 'text';
xhr.open('GET', 'https://www.google.com.pk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=real+madrid', true);
xhr.onload = function () {
 // console.log(xhr.responseURL); // http://example.com/test
  console.log(xhr.response);
  console.log(xhr.responseURL);
 };
xhr.send(null);

The xhr.response gives the source code of the page which does not contain the data i want and the xhr.responseURL gives the URL of google itself https://www.google.com.pk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8