Bypassing CORS, requesting news information from Google
I’ve been working on the CORS.ninja website for the last couple of months, it serves as an AJAX proxy to retrieve information from a remote server. All one needs to do is write an AJAX call to CORS.ninja with the URL and method parameters, and the return can either be JSON or JSONP.
For example to retrieve information from Google News Technology, which can be found at
https://news.google.com/news/section?pz=1&cf=all&topic=tc&siidp=65774f94d5dcda7d9806180c04684f7d770a&ict=ln
we construct an ajax call
function parse(){} var request_url = "https://news.google.com/news/section?pz=1&cf=all&topic=tc&siidp=65774f94d5dcda7d9806180c04684f7d770a&ict=ln"; $.ajax({ type: 'GET', url: 'http://www.cors.ninja/api/request', data:{url: request_url, method: 'GET'}, callback: 'parse', contentType:'application/json', dataType:'jsonp' });
The JSONP response from CORS.ninja will be
parse({ url: 'https://news.google.com/news/section?pz=1&cf=all&topic=tc&siidp=65774f94d5dcda7d9806180c04684f7d770a&ict=ln', status:'200', method: 'GET', body: '.....'; })
The JSONP callback function will then be executed with the response object. Within the callback we need to handle the response.
Assuming you are already including jQuery we can easily transform the body into actual DOM. Then it can easily be parsed and filtered.
function parse(data) { var dom = $.parseHTML(data.body); var titles = $(dom).find('.esc-lead-article-title-wrapper'); var articles = $(dom).find('.esc-lead-snippet-wrapper'); $.each(titles, function(idx,item,arr){ $('#holder').append(item); $('#holder').append(articles[idx]); }); };
Example can be found at
Cors.Ninja Google News Example
JS Fiddle Google News Example