开发者

Get google trends by date in php

By using this feed

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

we can get current tre开发者_开发技巧nds 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.


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? 
    // ...
}
?>


The accepted answer is no longer valid. After searching a lot I finally found a working PHP api to get google trends.

With this one you can look for graph, region and related queries from google trends in a range of time, this way:

$gs=new GSession($guser, $gpass);
$gs->authenticate();
$gt=new GTrends($gs, 'es');
$gt->addTerm('something1')->addTerm('something2')->setTime('2017-04-01 2017-04-19');
$gt->getGraph('csv'));

Edit: The library isn't free anymore, it has a cost of 28eur.


I know it is an old topic, but I created and recently updated this library:

https://github.com/gabrielfs7/google-trends

It supports search by region, interests over time, related topics and queries and does NOT require a Google Account to use it.

Example:

$searchFilter = (new GSoares\GoogleTrends\Search\SearchFilter())
    ->withCategory(0) //All categories
    ->withSearchTerm('hair')
    ->withLocation('US')
    ->withinInterval(
        new DateTimeImmutable('now -7 days'),
        new DateTimeImmutable('now')
    )
    ->withLanguage('en-US')
    ->considerWebSearch()
    # ->considerImageSearch() // Consider only image search
    # ->considerNewsSearch() // Consider only news search
    # ->considerYoutubeSearch() // Consider only youtube search
    # ->considerGoogleShoppingSearch() // Consider only Google Shopping search
    ->withTopMetrics()
    ->withRisingMetrics();

$result = (new GSoares\GoogleTrends\Search\RelatedQueriesSearch())
->search($searchFilter)
->jsonSerialize();

Response example:

{  
   "searchUrl":"http://www.google.com/trends/...",
   "totalResults":2,
   "results":[  
      {  
         "term":"hair salon",
         "ranking":100,
         "hasData": true,
         "searchUrl":"http://trends.google.com/..."
      },
      {  
         "term":"short hair",
         "ranking":85,
         "hasData": true,
         "searchUrl":"http://trends.google.com/..."
      }
   ]
}

It is possible to get the response as a JSON or PHP Objects. The code is 100% covered by tests and supports PHP7.2+.

Hope it can help someone who still searches for this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜