juust ~ php oddities

Unordered list of one element
  • rss
  • begin
  • about
    • vcard
    • WTF is BroJesus
  • php scripts
    • flickr wp widget
    • google multi key serp tool, php script
    • gwt plugin
  • php classes
    • php pagerank class
    • fibonacci class
    • robots.txt parser php class
  • serp
    • serp dashboard wordpress plugin
  • services

parsing the google trends atom feed

juust | 07/11/2008

Short and sweet : how to grab the google trends atom feed and parse out the links,
in 15 lines.

  1. $feed = simplexml_load_file('http://www.google.com/trends/hottrends/atom/hourly');
  2. $children =  $feed->children('http://www.w3.org/2005/Atom');
  3. $parts = $children->entry;
  4. foreach ($parts as $entry) {
  5.    $details = $entry->children('http://www.w3.org/2005/Atom');
  6.    $dom = new domDocument();
  7.    @$dom->loadHTML($details->content);
  8.    $anchors = $dom->getElementsByTagName('a');
  9.   foreach ($anchors as $anchor) {
  10.     $url = $anchor->getAttribute('href');
  11.     $urltext = $anchor->nodeValue;
  12.     echo 'Link: <a href="' . $url . '" title="' . $urltext . '">' . $urltext . '</a> ';
  13.   }
  14. }

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);

Categories
google, php
Tags
google, php, trends
Comments rss
Comments rss
Trackback
Trackback

« serp tool the value of google trends »

12 Responses to “parsing the google trends atom feed”

  1. Herman says:
    19/12/2008 at 1:38 pm

    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.

    Reply
  2. juust says:
    19/12/2008 at 5:00 pm

    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.

    Reply
  3. Herman says:
    21/12/2008 at 9:51 pm

    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

    Reply
  4. google trends II | juust (that's me) says:
    22/12/2008 at 3:51 am

    [...] 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 [...]

    Reply
  5. M.A.Dhavan says:
    22/06/2009 at 12:31 pm

    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.

    Reply
  6. wow gold says:
    08/08/2009 at 7:16 am

    good article , I added you in the ‘Liked’ category.. thanks for sharing the article!

    Reply
  7. Neo says:
    27/08/2009 at 8:47 am

    Thanks Dear
    You saved my life

    Reply
  8. SudoBash says:
    25/09/2009 at 4:12 pm

    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

    Reply
  9. Jorge A. Gonzalez says:
    30/11/2009 at 11:18 am

    cool. thanks.

    Reply
  10. Sbobet says:
    17/04/2010 at 8:35 pm

    Thank you. Few confused with simplexml and dom xml. But it solved now.

    Reply
  11. Solomon baldwin says:
    11/07/2010 at 7:36 am

    Thanks for the share and i think that i have an idea from your post. Thanks a lot

    Reply
  12. maple story mesos says:
    22/07/2010 at 2:32 pm

    good,thanks

    Reply

Leave a Reply

Click here to cancel reply.

Recent Posts

  • Pagerank sculpting session
  • wish you were here
  • interesting : seo panel
  • availability test
  • Mayday

click me!
rss
Comments rss
Blog Directory
Web Developement Blogs - BlogCatalog Blog Directory
Listed in LS Blogs the Blog Directory and Blog Search Engine
Blog Flux Directory
joopita.com free web directory and search engine
design by jide
sitemap
17241 confirmed spam kills