首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在php中按日期获取google趋势

在php中按日期获取google趋势
EN

Stack Overflow用户
提问于 2011-03-19 11:54:17
回答 3查看 7.3K关注 0票数 1

通过使用这个提要

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

我们可以了解谷歌目前的趋势。

但我需要得到前一天的趋势。当前趋势中的搜索词会经常发生变化,因此我试图在今天开始的时候获得前一天的趋势主题。

但我不知道网址有前一天的趋势吗?

有人能帮我解决这个问题吗?谢谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-03-19 12:02:02

你可以从这里试试这个:http://www.fromzerotoseo.com/scraping-google-hot-trends/

代码语言:javascript
复制
<?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? 
    // ...
}
?>
票数 2
EN

Stack Overflow用户

发布于 2017-04-19 06:10:08

接受的答案不再有效。经过大量的搜索,我终于找到了一个工作的PHP获取google趋势

使用此方法,您可以在一定时间内从google趋势中查找图形、区域和相关查询,方式如下:

代码语言:javascript
复制
$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'));

编辑:图书馆不再是免费的了,它的成本是28欧元。

票数 2
EN

Stack Overflow用户

发布于 2020-03-30 12:29:36

我知道这是一个老话题,但我创建并更新了这个库:

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

它支持区域搜索,随时间推移的兴趣,相关的主题和查询,不需要谷歌帐户使用它。

示例:

代码语言:javascript
复制
$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();

回应例子:

代码语言:javascript
复制
{  
   "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/..."
      }
   ]
}

可以以JSON或PHP对象的形式获得响应。该代码100%包含在测试中并支持PHP7.2+。

希望它能帮助那些还在寻找这个的人。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5361884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档