Google News RSS feed API with Images

I'm using "" to avoid cors origin issue when ever hitting a third party domain. Next using google provided api to fetch news articles as rss feed in xml format via url ""+srch+"&hl=en-IN&gl=IN&ceid=IN:en".

In order to get image with the article is to hit the news website and searching for og:image where most of the websites uses it for sharing in social media websites to show image in post, we find it and uses it in our website.

Only that you need to replace 'srch' with your own search query in a string format. Below is the code I used for my website celebrityhub you can visit it if you like.

                        url: ""+srch+"&hl=en-IN&gl=IN&ceid=IN:en",
                        success: function(resp){
                            var xml = resp;
                            // console.log("xml", $(xml));
                            $.each($(xml)[0].childNodes[0].childNodes[0].childNodes, function(index, val) {
                                 /* iterate through array or object */
                                 if(index >= 8){
                                     var articleImgSrc = "";
                                         url: ""+val.childNodes[1].childNodes[0].nodeValue,
                                         success: function(htmlResp){
                                             var resp = JSON.stringify(htmlResp);
                                             var titlePos ="og:image");
                                             var imgConStr = resp.slice(titlePos, titlePos+150);
                                             var imgPos ="content=");
                                             var imgLink = imgConStr.slice(11+10,".jpg")+4);
                                                 imgLink = "dummyimg.jpg"
                                             $("#googlefeed").append("<div class=' col-md-6'><div class=' col-md-6'><img src='"+imgLink+"' width='300px' height='250px' onerror='this.onerror=null;this.src=\"dummyimg.jpg\"'>&nbsp;</div><div class=' col-md-6'>"+val.childNodes[4].firstChild.nodeValue+"</div></div>");

Also in some cases we not able to get the image url from the source website, so instead for such scenarios we can use any dummyimg you like instead. So that it wont show as broken.

Here is the example to showcase how it might look like:
So that is it folks, for any queries please do post your comments below and I will let you find your solution ASAP.

Other Similar Blog Post:

YouTube Channel Videos RSS Feed API 

SEO Tags: google news rss feed url,  link, api, website, limit, example, parameters, feeds list, generator.


Feel free to ask your queries, happy to discuss with you.

  1. This comment has been removed by a blog administrator.

    1. It is always good to leave the work to the professionals. They know what they are doing most of the time.

  2. You will show up at the Advanced Image Search page. The essential set up of this page is channel terms are shown off to one side and drop-down arrangements of decisions for each channel is shown off to the right side.


Post a Comment

Feel free to ask your queries, happy to discuss with you.