parsing the google trends atom feed
juust | 07/11/2008Short and sweet : how to grab the google trends atom feed and parse out the links,
in 15 lines.
-
$feed = simplexml_load_file('http://www.google.com/trends/hottrends/atom/hourly');
-
$children = $feed->children('http://www.w3.org/2005/Atom');
-
$parts = $children->entry;
-
foreach ($parts as $entry) {
-
$details = $entry->children('http://www.w3.org/2005/Atom');
-
$dom = new domDocument();
-
@$dom->loadHTML($details->content);
-
$anchors = $dom->getElementsByTagName('a');
-
foreach ($anchors as $anchor) {
-
$url = $anchor->getAttribute('href');
-
$urltext = $anchor->nodeValue;
-
echo 'Link: <a href="' . $url . '" title="' . $urltext . '">' . $urltext . '</a> ';
-
}
-
}
Requires php with simplexml and dom xml. You could use it for a blogfarm script but that’s about all I can think of.
edited 18-12-08 :
$dom->loadHTML((string) $details->content);
to
@$dom->loadHTML($details->content);









Hi,
Can you explain how to install this script step by step.
I tried to using this script in my site but i found warning like this
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ‘;’ in Entity, line: 2 in /home/username/public_html/gtrends.php on line 8
Whats wrong?
Thanks for your time to read this comment.
Hi Herman, I encountered the same problem. Adding @ to suppress errors solves it, I just forgot to add it to this snippet. Sorry for the inconvenience, and thanks for the feedback.
Wow fasted replay two thumb up for you. Problem solved now many thanks for you juust.
Hi just i`m newbie in php (less kowledge about PHP) and i want ask do you know how to display result google trends details still open in my site?
Example case i have a site http://www.examplesite.com and at this time (moment writing this comment) the hottest keyword in google trends is Bob Bowersox. How to made it become http://www.examplesite.com/bob_bowersox. So we not must visit google.com/trends to know details what the hottest topic/keyword today because all has provide in my site. I found some site can do it such as http://trendfo.com or http://utube.smashits.com/hot-trends-from-world.htmlutube.smashits.com/hot-trends-from-world.html
I enjoy with your site because in this place i can learn more about PHP and can found more php script that very usefull. Thanks for share juust and keep posted :)
Best Regards
[...] site, but a ‘comment’ box isn’t fit for it so I’ll put the reply here. The question was about creating ’search engine friendly’ descriptive URL’s based on keywords [...]
Thank you Sir…
I was searching on the net the whole day for a solution to parse the google hot trends.
I tried several scripts and failed.
Finally I got your script. Its really cool, simple and efficient, which works pretty nice.
Thank you once again.
Keep writing useful scripts.
good article , I added you in the ‘Liked’ category.. thanks for sharing the article!
Thanks Dear
You saved my life
I made a google trends parser with C++ but it does a few extra things and runs on any Linux/Unix/BSD platform with ease. It uses wget to download and separates the keywords for you into two files a plain text and a single line file that always contains the latest keywords of the hour and it even makes pages that recognize certain words like video and episode… Check the completely automated output at:
http://www.nflspot.com/hot/HotSearches.html
or
http://www.theviruscure.com/HotSearches.html
cool. thanks.
Thank you. Few confused with simplexml and dom xml. But it solved now.
Thanks for the share and i think that i have an idea from your post. Thanks a lot
good,thanks