Bring Yahoo News to your sites
------------------------------------

Simply paste this code into your .cfm page and bring in Yahoo News into your site. To change
the search criteria, simply go to Yahoo News ( http://news.search.yahoo.com ) add your search
criteria and click Search, the results display along with a button on the right that says
"View as RSS". Click this and copy the resulting Url and paste it into your version of the below script.


<!--- 
    Author : David McGraw 
    Date : 04/15/2005
    Yahoo News RSS Feed
--->


<cfhttp url="http://news.search.yahoo.com/news/rss?ei=UTF-8&p=Coldfusion"></cfhttp>
<cfset myXMLDocument = XmlParse(cfhttp.fileContent)>

<cfoutput>

<table border="0" cellspacing="2" width="600">
    <tr>
   
     <td><strong>News</strong></td>
    </tr>
    <tr>
        <td>
<hr size="1" width="100%"></td>
    </tr>

    <cfloop from="1" to="#ArrayLen(myXMLDocument.rss.channel.XMLChildren)#" index="i">
        <cfif myXMLDocument.rss.channel.XMLChildren[i].XMLName
EQ "item">
            <cfset NewsItem = myXMLDocument.rss.channel.XMLChildren[
i]>

            <cfloop from=
"1" to="#ArrayLen(NewsItem.XMLChildren)#" index="x">

                <cfif NewsItem.XMLChildren[x].XMLName
EQ "Title">

                <tr>
                    <td>
<strong>#NewsItem.XMLChildren[x].XMLText#</strong></td>
                </tr>

        <cfelseif NewsItem.XMLChildren[x].XMLName EQ "link">

            <cfset XMLLink = MID(NewsItem.XMLChildren[
x].XMLtext, Find("http%3A//",NewsItem.XMLChildren[x].XMLtext,1)+9, Val(Find("http%3A//",NewsItem.XMLChildren[x].XMLtext,1)+9 + Len(NewsItem.XMLChildren[x].XMLtext)))>
                <tr>
                    <td>
Link : <a href="http://#XMLLink#">#XMLLink#</a></td>
                </tr>


        <cfelseif NewsItem.XMLChildren[x].XMLName EQ "Description">

                <tr>
                    <td colspan=
"4">#NewsItem.XMLChildren[x].XMLText#</td>
                </tr>

        <cfelseif NewsItem.XMLChildren[x].XMLName EQ "pubDate">

                <tr>
                    <td colspan=
"4">Publish Date: <em>#NewsItem.XMLChildren[x].XMLText#</em></td>
                </tr>


        </cfif>

    </cfloop>
    <tr>
        <td>
<br></td>
    </tr>
    </cfif>
    </cfloop>

    <tr>
        <td align=
"right"><em>#myXMLDocument.rss.channel.Title.XMLText# <br> #myXMLDocument.rss.channel.copyright.XMLText# </em></td>
    </tr>

</table>

</cfoutput>

About This Tutorial
Author: David McGraw
Skill Level: Beginner 
 
 
 
Platforms Tested: CFMX
Total Views: 29,088
Submission Date: April 15, 2005
Last Update Date: June 05, 2009
All Tutorials By This Autor: 1
Discuss This Tutorial
  • I just used this code on a wine site and it worked famously! Thank you Dave for posting it. I just got done reading an article about how RSS feeds re-published on your site doesn't have any SEO penalty for duplicate content. With that being said, I would like to pull entire articles into my website for better user experience instead of just the headlines linking away. Is this possible? - Lou Lynch

  • If your having issues with this, especiaaly with the error some are reporting, be sure you dump the VAR cfhttp.fileContent, make sure you are getting an RSS feed from Yahoo...As long as you are getting an RSS feed from Yahoo, you will not recieve that error. If that doesnt work, I do not understand why it is not working for you, its works perfectly on my site http://www.vitalpodcasts.com good luck.

  • This doesnt work " Document root element is missing. Document root element is missing. The error occurred on line 3. " ???

  • The Code does not seems to work as it is ahowing an error code: Doument root element is Missing, Help me to get ans wer

  • I believe that the use of this is against their policy for commercial sites. Please check before adding this to your site. On yahoo's terms of service page it states the following: What are the terms of use? The feeds are provided free of charge for use by individuals and non-profit organizations for personal, non-commercial uses. We ask that you provide attribution to Yahoo! News in connection with your use of the feeds. If you provide this attribution in text, please use: "Yahoo! News." If you provide this attribution with a graphic, please use the Yahoo! News logo that we have included in the feed itself. We reserve all rights in and to the Yahoo! News logo, and your right to use the Yahoo! News logo is limited to providing attribution in connection with these RSS feeds. We are also including the provider of each individual news story in the feed alongside each headline. Please do not alter this for display. We want our news partners to be attributed for their work. Yahoo! News also reserves the right to require you to cease distributing these feeds at any time for any reason.

Advertisement

Sponsored By...
Powered By...