...

View Full Version : Pull information from google news feed



Meltdown
05-11-2008, 11:22 PM
<?
$xml = simplexml_load_file('http://news.google.com/news?hl=en&q=miley+cyrus&ie=UTF-8&output=rss&ned=:ePkh8BM9EwLbwWvA4sRqZGpmbuEx-6gZ3LY8iJUsQkypOUgWM4CthtlqJHDh4MRCh-2MItWSy3kem-3S-MUGVP-LjTUnPzkxBwBrNRar');
//print_r($xml);
echo "<hr>";
foreach ($xml as $status) {
$title = $status->entry->title;
$link = $status->entry->link;
$test = $status->title;
echo "$title";
echo "<br>$test (to see if the feed is even being read...and it is)";
echo "<br>Link: $link";
}
?>
What I want to do: pull the data from the feed so I can manipulate it how I want.
What's not working: I can pull the title of the feed from the feed but nothing else. Here is how I think the feel is structured:

<?xml version="1.0" encoding="UTF-8"?>
<feed version="0.3" xml:lang="en" xmlns="http://purl.org/atom/ns#">
<generator>NFE/1.0</generator>
<title>miley cyrus - Google News </title>
<link rel="alternate" type="text/html" href="http://news.google.com/news?hl=en&amp;q=miley+cyrus&amp;ie=UTF-8&amp;ned=:ePkh8BM9EwLbwWvA4sRqZGpmbuEx-6gZ3LY8iJUsQkypOUgWM4CthtlqJHDh4MRCh-2MItWSy3kem-3S-MUGVP-LjTUnPzkxBwBrNRar.xml"/>
<tagline>miley cyrus - Google News </tagline>
<author>
<name>Google Inc.</name>
<email>news-feedback@google.com</email>
</author>
<copyright>&amp;copy;2008 Google</copyright>
<modified>2008-05-11T18:53:50Z</modified>
<entry>
<title type="text/html" mode="escaped">blah</title>
<link rel="alternate" type="text/html" href="blahblahblah.com"/>
<id>tag:news.google.com,2005:cluster=482dc827</id>
<issued>2008-05-11T07:43:40Z</issued>
<modified>2008-05-11T07:43:40Z</modified>
<content type="text/html" mode="escaped"> and content here and so on and so forth.

I don't understand what's going on.

_Aerospace_Eng_
05-11-2008, 11:36 PM
You can always navigate to the feed directly and go to view source you know to see its structure.

Meltdown
05-11-2008, 11:37 PM
..that's how I got what I posted. But it still isn't working. So either I'm overlooking something very simple or I'm way off track.

_Aerospace_Eng_
05-11-2008, 11:47 PM
Thats not how the feed is structured. You got some of it right. This is what I saw when I went directly to the source of the feed.

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<generator>NFE/1.0</generator>
<title>miley cyrus - Google News</title>
<link>http://news.google.com/news?hl=en&amp;q=miley+cyrus&amp;ie=UTF-8&amp;ned=:ePkh8BM9EwLbwWvA4sRqZGpmbuEx-6gZ3LY8iJUsQkypOUgWM4CthtlqJHDh4MRCh-2MItWSy3kem-3S-MUGVP-LjTUnPzkxBwBrNRar</link>
<language>en</language>
<webMaster>news-feedback@google.com</webMaster>
<copyright>&amp;copy;2008 Google</copyright>
<pubDate>Sun, 11 May 2008 22:33:56 GMT</pubDate>
<lastBuildDate>Sun, 11 May 2008 22:33:56 GMT</lastBuildDate>
<image>
<title>miley cyrus - Google News</title>
<url>http://news.google.com/intl/en_us/images/news_res.gif</url>
<link>http://news.google.com/</link>
</image>
<item>
<title>Meghan O&amp;#39;Rourke: The real Miley Cyrus tragedy - Dallas Morning News</title>
<link>http://news.google.com/news/url?sa=T&amp;ct=us/0-0&amp;fd=R&amp;url=http://www.dallasnews.com/sharedcontent/dws/dn/opinion/points/stories/DN-orourke_11edi.ART.State.Edition1.466dbb8.html&amp;cid=1210959911&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzeU9 bfFhiDNMTGxXRC8leoETE8rIA</link>
<guid isPermaLink="false">tag:news.google.com,2005:cluster=482dc827</guid>
<pubDate>Sun, 11 May 2008 07:43:40 GMT</pubDate>
<description>&lt;table border=0 width= valign=top cellpadding=2 cellspacing=7&gt;&lt;tr&gt;&lt;td width=80 align=center valign=top&gt;&lt;font style=&quot;font-size:85&#37;;font-family:arial,sans-serif&quot;&gt;&lt;a href=&quot;http://news.google.com/news/url?sa=T&amp;ct=us/0i-0&amp;fd=R&amp;url=http://www.katu.com/news/entertainment/18561809.html&amp;cid=1210959911&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzdcXZhepHFsQ-1JBh_kHQ8d4-RqRw&quot;&gt;&lt;img src=http://news.google.com/news?imgefp=gpju25FOW2EJ&amp;imgurl=media.katu.com/images/080504_miley_cyrus.jpg width=80 height=60 alt=&quot;&quot; border=1&gt;&lt;br&gt;&lt;font size=-2&gt;KATU&lt;/font&gt;&lt;/a&gt;&lt;/font&gt;&lt;/td&gt;&lt;td valign=top class=j&gt;&lt;font style=&quot;font-size:85%;font-family:arial,sans-serif&quot;&gt;&lt;br&gt;&lt;div style=&quot;padding-top:0.8em;&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;1&quot; width=&quot;1&quot;&gt;&lt;/div&gt;&lt;div class=lh&gt;&lt;a href=&quot;http://news.google.com/news/url?sa=T&amp;ct=us/0-0&amp;fd=R&amp;url=http://www.dallasnews.com/sharedcontent/dws/dn/opinion/points/stories/DN-orourke_11edi.ART.State.Edition1.466dbb8.html&amp;cid=1210959911&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzeU9 bfFhiDNMTGxXRC8leoETE8rIA&quot;&gt;Meghan O&amp;#39;Rourke: The real &lt;b&gt;Miley Cyrus&lt;/b&gt; tragedy&lt;/a&gt;&lt;br&gt;&lt;font size=-1&gt;&lt;font color=#6f6f6f&gt;Dallas Morning News,&amp;nbsp;TX&amp;nbsp;-&lt;/font&gt; &lt;nobr&gt;14 hours ago&lt;/nobr&gt;&lt;/font&gt;&lt;br&gt;&lt;font size=-1&gt;Call me insensitive, but I didn&amp;#39;t think that the supposedly &amp;quot;racy&amp;quot; photo of &amp;#39;tween star &lt;b&gt;Miley Cyrus&lt;/b&gt; holding a bedsheet around her bare torso was as outr&#233; as &lt;b&gt;...&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;font size=-1&gt;&lt;a href=&quot;http://news.google.com/news/url?sa=T&amp;ct=us/0-1&amp;fd=R&amp;url=http://www.eonline.com/uberblog/marc_malkin/b136171_miley_cyrus_new_singing_partner.html&amp;cid=1210959911&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzcZx1-RaGz38fSS9faB8ItmCcyA6A&quot;&gt;&lt;b&gt;Miley Cyrus&lt;/b&gt;&amp;#39; New Singing Partner&lt;/a&gt; &lt;font size=-1 color=#6f6f6f&gt;&lt;nobr&gt;E! Online&lt;/nobr&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font size=-1&gt;&lt;a href=&quot;http://news.google.com/news/url?sa=T&amp;ct=us/0-2&amp;fd=R&amp;url=http://www.celebrity-gossip.net/celebrities/hollywood/miley-cyrus-new-singing-partner-204685/&amp;cid=1210959911&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzeuNLcYNO4hKZsTLggGlq9RcVL0SA&quot;&gt;&lt;b&gt;Miley Cyrus&lt;/b&gt;: New Singing Partner?&lt;/a&gt; &lt;font size=-1 color=#6f6f6f&gt;&lt;nobr&gt;The Gossip Girls&lt;/nobr&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font size=-1&gt;&lt;a href=&quot;http://news.google.com/news/url?sa=T&amp;ct=us/0-3&amp;fd=R&amp;url=http://justjared.buzznet.com/2008/05/10/miley-cyrus-john-travolta/&amp;cid=1210959911&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzdVj9AGK12BK2Xp_ux1ib7TCo3VGA&quot;&gt;&lt;b&gt;Miley Cyrus&lt;/b&gt; &amp;amp; John Travolta Duet in the Works?&lt;/a&gt; &lt;font size=-1 color=#6f6f6f&gt;&lt;nobr&gt;Just Jared&lt;/nobr&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font size=-1 class=p&gt;&lt;a href=&quot;http://news.google.com/news/url?sa=T&amp;ct=us/0-4&amp;fd=R&amp;url=http://www.theglobeandmail.com/servlet/story/RTGAM.20080509.wdiary0510/BNStory/SpecialEvents2&amp;cid=1210959911&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzeTfvWn6fjrjYf_wFjUwYTwom2Zlw&quot;&gt;&lt;nob r&gt;Globe and Mail&lt;/nobr&gt;&lt;/a&gt;&amp;nbsp;- &lt;a href=&quot;http://news.google.com/news/url?sa=T&amp;ct=us/0-5&amp;fd=R&amp;url=http://www.pr-inside.com/cyrus-dismisses-scandal-over-racy-myspace-r581899.htm&amp;cid=1210959911&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzcYwohRciT257jQHRX8mKh5ImiT4Q&quot;&gt;&lt;nobr&gt;P R-Inside.com (Pressemitteilung)&lt;/nobr&gt;&lt;/a&gt;&lt;/font&gt;&lt;br/&gt;&lt;font class=p size=-1&gt;&lt;a class=p href=http://news.google.com/news?hl=en&amp;ie=UTF-8&amp;ned=:ePkh8BM9EwLbwWvA4sRqZGpmbuEx-6gZ3LY8iJUsQkypOUgWM4CthtlqJHDh4MRCh-2MItWSy3kem-3S-MUGVP-LjTUnPzkxBwBrNRar&amp;ncl=1210959911&gt;&lt;nobr&gt;all 434 news articles&lt;/nobr&gt;&lt;/a&gt;&lt;/font&gt;&lt;/div&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</description>
</item>
<item>
<title>Hugh Hefner wants Miley Cyrus for Playboy. - Fashion.ie</title>
<link>http://news.google.com/news/url?sa=T&amp;ct=us/1-0&amp;fd=R&amp;url=http://www.fashion.ie/aggregator/gossip/73989-hugh-hefner-wants-miley-cyrus-playboy&amp;cid=1211449127&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzeDgDVxxAGB5YGX7-RJaF7DZ35-mA</link>
<guid isPermaLink="false">tag:news.google.com,2005:cluster=48353f27</guid>
<pubDate>Sun, 11 May 2008 17:09:49 GMT</pubDate>
<description>&lt;table border=0 width= valign=top cellpadding=2 cellspacing=7&gt;&lt;tr&gt;&lt;td width=80 align=center valign=top&gt;&lt;font style=&quot;font-size:85%;font-family:arial,sans-serif&quot;&gt;&lt;a href=&quot;http://news.google.com/news/url?sa=T&amp;ct=us/1i-0&amp;fd=R&amp;url=http://thecelebritytruth.com/miley-cyrus-apologizes-for-racy-photos/001485&amp;cid=1211449127&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzfiZlF656MeYp9yc4ckkDzkZyMk8w&quot;&gt;&lt;img src=http://news.google.com/news?imgefp=hG1W7EbOKHMJ&amp;imgurl=thecelebritytruth.com/assets/Uploads/Miley-Cyrus-Disney-Bob-DAmico.jpg width=80 height=67 alt=&quot;&quot; border=1&gt;&lt;br&gt;&lt;font size=-2&gt;The Celebrity Truth&lt;/font&gt;&lt;/a&gt;&lt;/font&gt;&lt;/td&gt;&lt;td valign=top class=j&gt;&lt;font style=&quot;font-size:85%;font-family:arial,sans-serif&quot;&gt;&lt;br&gt;&lt;div style=&quot;padding-top:0.8em;&quot;&gt;&lt;img alt=&quot;&quot; height=&quot;1&quot; width=&quot;1&quot;&gt;&lt;/div&gt;&lt;div class=lh&gt;&lt;a href=&quot;http://news.google.com/news/url?sa=T&amp;ct=us/1-0&amp;fd=R&amp;url=http://www.fashion.ie/aggregator/gossip/73989-hugh-hefner-wants-miley-cyrus-playboy&amp;cid=1211449127&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzeDgDVxxAGB5YGX7-RJaF7DZ35-mA&quot;&gt;Hugh Hefner wants &lt;b&gt;Miley Cyrus&lt;/b&gt; for Playboy.&lt;/a&gt;&lt;br&gt;&lt;font size=-1&gt;&lt;font color=#6f6f6f&gt;Fashion.ie,&amp;nbsp;Ireland&amp;nbsp;-&lt;/font&gt; &lt;nobr&gt;5 hours ago&lt;/nobr&gt;&lt;/font&gt;&lt;br&gt;&lt;font size=-1&gt;Hugh Hefner isn’t shy in wanting to tap &lt;b&gt;Miley Cyrus&lt;/b&gt; for Playboy. Lets face it, she probably could do worse will do worse considering the pace she is on. &lt;b&gt;...&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;font size=-1&gt;&lt;a href=&quot;http://news.google.com/news/url?sa=T&amp;ct=us/1-1&amp;fd=R&amp;url=http://fametastic.co.uk/archive/20080511/11280/hugh-hefner-offers-miley-cyrus-a-playboy-shoot-once-she-turns-18/&amp;cid=1211449127&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzevCGSDEqdnqPwIRc7k3AK4f7QfmA&quot;&gt;Hugh Hefner offers &lt;b&gt;Miley Cyrus&lt;/b&gt; a Playboy shoot - once she turns 18&lt;/a&gt; &lt;font size=-1 color=#6f6f6f&gt;&lt;nobr&gt;Fametastic&lt;/nobr&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font size=-1&gt;&lt;a href=&quot;http://news.google.com/news/url?sa=T&amp;ct=us/1-2&amp;fd=R&amp;url=http://sundaygazettemail.com/News/200805090407&amp;cid=1211449127&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzdWp1guQGtjiOkwm-KKAudse7F2hQ&quot;&gt;&lt;b&gt;Miley Cyrus&lt;/b&gt; reader response&lt;/a&gt; &lt;font size=-1 color=#6f6f6f&gt;&lt;nobr&gt;Charleston Gazette&lt;/nobr&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font size=-1&gt;&lt;a href=&quot;http://news.google.com/news/url?sa=T&amp;ct=us/1-3&amp;fd=R&amp;url=http://blogs.reuters.com/fanfare/2008/05/09/hefner-wants-miley-cyrus-for-playboy-when-shes-legal/&amp;cid=1211449127&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzd6Cfl6h16AZHZxiKL2fMeWZlH4qg&quot;&gt;Hefner wants &lt;b&gt;Miley Cyrus&lt;/b&gt; for Playboy - when she’s legal!&lt;/a&gt; &lt;font size=-1 color=#6f6f6f&gt;&lt;nobr&gt;Reuters UK&lt;/nobr&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font size=-1 class=p&gt;&lt;a href=&quot;http://news.google.com/news/url?sa=T&amp;ct=us/1-4&amp;fd=R&amp;url=http://www.efluxmedia.com/news_Hefner_Wants_Miley_Cyrus_in_Playboy_17415.html&amp;cid=1211449127&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFr qEzfqWpsr_Zj8lEllX0VJv-r04uzJBA&quot;&gt;&lt;nobr&gt;eFluxMedia&lt;/nobr&gt;&lt;/a&gt;&amp;nbsp;- &lt;a href=&quot;http://news.google.com/news/url?sa=T&amp;ct=us/1-5&amp;fd=R&amp;url=http://www.nationalledger.com/artman/publish/article_272620483.shtml&amp;cid=1211449127&amp;ei=VHQnSKXhH4_w8AS8haiTAw&amp;usg=AFrqEzcDWsO87MXDnZDJiP7lH-UNllMssA&quot;&gt;&lt;nobr&gt;National Ledger&lt;/nobr&gt;&lt;/a&gt;&lt;/font&gt;&lt;br/&gt;&lt;font class=p size=-1&gt;&lt;a class=p href=http://news.google.com/news?hl=en&amp;ie=UTF-8&amp;ned=:ePkh8BM9EwLbwWvA4sRqZGpmbuEx-6gZ3LY8iJUsQkypOUgWM4CthtlqJHDh4MRCh-2MItWSy3kem-3S-MUGVP-LjTUnPzkxBwBrNRar&amp;ncl=1211449127&gt;&lt;nobr&gt;all 64 news articles&lt;/nobr&gt;&lt;/a&gt;&lt;/font&gt;&lt;/div&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</description>
</item>
</channel>
</rss>

Meltdown
05-11-2008, 11:55 PM
ahh. How embarrassing. I must've been half asleep when I copied fro the feed source (otherwise, I don't know how I could've made such a mistake)

Anyway, so this thread isn't a complete waste, I'll post an updated, working version of my original code:


<?
$xml = simplexml_load_file('http://news.google.com/news?hl=en&q=miley+cyrus&ie=UTF-8&output=rss&ned=:ePkh8BM9EwLbwWvA4sRqZGpmbuEx-6gZ3LY8iJUsQkypOUgWM4CthtlqJHDh4MRCh-2MItWSy3kem-3S-MUGVP-LjTUnPzkxBwBrNRar');
foreach ($xml as $status) {
$title = $status->item->title;
$link = $status->item->link;
echo "$title<br>$link";

}
?>

Nates
06-13-2008, 10:11 PM
Does anyone know what would need to be added to show the latest 10 headlines.

I have this code working but its only shows 1 link

<?

$xml = simplexml_load_file('http://news.google.com/news?geo=90210&output=rss&ned=:ePkh8BM9EwLbocwl5pRallqUU6ngkZmTU6yj4OyooxAa7OjEamlgZGjg8X6aDsQNilwivvlFRZnFZUB1qToKYSFQdQamZma GHp-71ODOzIO4lUWIKTVHiAHiZjCVC3PwLzag1C821pz85MQcAA4IIOk');
foreach ($xml as $status) {
$link = $status->item->link;
$description = $status->item->description;

echo "$description <br> ";

}
?>

Thanks for any feedback

Nate

Meltdown
06-13-2008, 10:28 PM
$xml = simplexml_load_file('');
print_r($xml);
format as desired.

Nates
06-13-2008, 10:43 PM
Meltdown,

Thanks for the quick reply.

Tried this:

<?

$xml = simplexml_load_file('http://news.google.com/news?geo=90210&output=rss&ned=:ePkh8BM9EwLbocwl5pRallqUU6ngkZmTU6yj4OyooxAa7OjEamlgZGjg8X6aDsQNilwiv vlFRZnFZUB1qToKYSFQdQamZmaGHp-71ODOzIO4lUWIKTVHiAHiZjCVC3PwLzag1C821pz85MQcAA4IIOk');
print_r($xml);
foreach ($xml as $status) {
$link = $status->item->link;
$description = $status->item->description;

echo "$description <br> ";

}
?>

--------------

and it does display 10 results but also getting errors like below

) [3] => SimpleXMLElement Object ( [title] => SAG deal in June? Don't count on it - Hollywood Reporter [link] => http://news.google.com/news/url?sa=T&ct=us/3-0&fd=R&url=http://hollywoodreporter.com/hr/content_display/news/e3id5f52df31901946c211cc22eebb40f92&#37;3Fimw%3DY&cid=1221923963&ei=vOlSSKuaMp-q9gSp06z-Cw&usg=AFQjCNGgcU9C5EspYSOGjS-i2csstYUHJw [guid] => tag:news.google.com,2005:cluster=48d5147b [pubDate] => Fri, 13 Jun 2008 05:32:17 GMT [description] =>

Meltdown
06-13-2008, 11:40 PM
that's not error.
that's raw.
like i said, you'll need to do your own formatting to tidy things up.
look it up:
http://php.net/simple_xml_loadfile

Nates
06-14-2008, 01:01 AM
Yea, thanks for the link...I was able to figure it out.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum