本文整理汇总了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]);