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', 'google.com.pk/webhp', true);
xhr.onload = function () {
// console.log(xhr.responseURL); // 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 google.com.pk/webhp
Anwesh Mishra
thefootbook.in
i think it is not possible with the help of an ajax call as browser prevents from other origins(See CORS developer.mozilla.org/en-US/docs/Web/HTTP/Access_…) is not supported. What i do in nodejs i do an ajax call to an endpoint in my server and then load the results with the help of request module and once the fetching of results is complete i return the results to the client. In sort you want to create an API in your server side which can fetch results from google server and from google server in the client side you can make a request to your server to load the results from google with the help of the api you created. In short you have scrape results from server side. Since you are using php I found a good web scraper in php https://github.com/FriendsOfPHP/Goutte. Here is the basic idea
client -> Server(your server) ->google.com
client to server the communication will be with the help of ajax and then server to google.com will be with the help of web scraper