VKGS VKGS - 19 days ago 7
PHP Question

Get google trends by date in php

By using this feed


http://www.google.co.in/trends/hottrends/atom/hourly


we can get current trends in google.

But am in need to get previous day trends. search terms in current trends will change often, so that i tried to get previous day trending topics on start of the current day.

But i dont aware of the url to get previous day trends?

Any body can get me out this problem? Thanks.

Kit Kit
Answer

You could try this from here: http://www.fromzerotoseo.com/scraping-google-hot-trends/

<?php
// Scraping New Year’s Eve
$result = getPage(
    '[proxy IP]:[port]',
    'http://www.google.com/trends/hottrends?sa=X&date=2008-12-31',
    'http://www.google.com/trends/hottrends?sa=X',
    'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8',
    1,
    5);

if (empty($result['ERR'])) {    
    preg_match_all(
        '(<td class=num>\d+\.</td>.*<td><a href="(.*)">(.*)</a></td>)siU',
        $result['EXE'], $matches);

    // some URL tuning here…
    for ($i = 0; $i < count($matches[1]); $i++) {
        $matches[1][$i] = 'http://www.google.com' . $matches[1][$i];
    }

    // Job's done! 
    // $matches[1] array contains all URLs, and 
    // $matches[2] array contains all anchors
} else {
    // WTF? Captcha or network problems? 
    // ...
}
?>
Comments