inbo/google-crawler

一个用于获取谷歌结果的简单爬虫

v2.0.3 2019-05-21 01:26 UTC

README

Latest Stable Version Build Status Code Coverage Scrutinizer Code Quality License

一个用于获取谷歌结果的简单爬虫。

此组件可用于检索搜索词的前100个结果。

由于谷歌检测到爬虫并在发出多次请求时阻止IP,因此此组件已准备使用一些在线代理服务,例如hide.me。

安装

使用以下命令安装最新版本

$ composer require cviniciussdias/google-crawler

用法

爬虫类构造函数原型

CViniciusSDias\GoogleCrawler\Crawler::__construct(
    SearchTermInterface $searchTerm, GoogleProxyInterface $proxy = null,
    string $googleDomain = 'google.com', string $countryCode = ''
)

参数

  • $searchTerm 将在谷歌上搜索的术语
  • $proxy 将用于访问谷歌的在线代理服务 [可选]
  • $googleDomain 您所在国家的特定谷歌域名,例如google.de、google.com.br等。 [可选]
  • $countryCode 将添加到谷歌url上的gl参数的国家代码,表示搜索位置。例如,'BR'、'US'、'DE' [可选]

示例

无代理

<?php
use CViniciusSDias\GoogleCrawler\{
    Crawler, SearchTerm
};

$searchTerm = new SearchTerm('Test');
$crawler = new Crawler($searchTerm); // or new Crawler($searchTerm, new NoProxy());

$resultList = $crawler->getResults();

使用某些代理

<?php
use CViniciusSDias\GoogleCrawler\{
    Crawler, SearchTerm, Proxy\CommonProxy
};

$searchTerm = new SearchTerm('Test');
$commonProxy = new CommonProxy('https://us.hideproxy.me/includes/process.php?action=update');
$crawler = new Crawler($searchTerm, $commonProxy);

$resultList = $crawler->getResults();

代理的更多细节

要了解更多关于当前支持哪些代理的详细信息,请参阅tests/Functional文件夹中的文件。在那里您将看到所有可用的代理。

遍历结果

foreach ($resultList as $result) {
    $title = $result->getTitle();
    $url = $result->getUrl();
    $description = $result->getDescription();
}

关于

要求

  • 此组件与PHP 7.2或更高版本一起工作
  • 此组件需要安装 php-ds 扩展

作者

Vinicius Dias (ZCE) - carlosv775@gmail.com - https://github.com/CViniciusSDias/ - http://www.zend.com/en/yellow-pages/ZEND030134

许可

此组件根据GPL v3.0许可证授权 - 有关详细信息,请参阅LICENSE文件