本文整理匯總了PHP中Goutte\Client::getCrawler方法的典型用法代碼示例。如果您正苦於以下問題:PHP Client::getCrawler方法的具體用法?PHP Client::getCrawler怎麽用?PHP Client::getCrawler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Goutte\Client
的用法示例。
在下文中一共展示了Client::getCrawler方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: Crawler
<?php
include "vendor/autoload.php";
use Goutte\Client;
use Symfony\Component\DomCrawler\Crawler;
if ($mock = false) {
$crawler = new Crawler();
$crawler->addHtmlContent(file_get_contents('example.html'));
} else {
$client = new Client();
$client->request('GET', 'http://habrahabr.ru/company/innopolis_university/blog/236647/');
$crawler = $client->getCrawler();
}
$users = [];
$crawler->filter('.comment_body')->each(function (Crawler $node) use(&$users) {
preg_match_all('/([a-f0-9]{32})/', $node->text(), $matches);
if ($matches[1]) {
$user = $node->filter('.username')->first()->text();
foreach ($matches[1] as $md5) {
$users[$user][] = $md5;
}
}
});
$answers = [];
for ($i = 0; $i <= 99; $i++) {
$answer = str_pad($i, 2, '0', STR_PAD_LEFT);
foreach ($users as $user => $md5List) {
foreach ($md5List as $k => $md5) {
if (md5($user . $answer) == $md5) {
$answers[$answer][] = $user;
unset($users[$user][$k]);