laravel 5 的简单 html dom 解析器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29067113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:40:56  来源:igfitidea点击:

Simple html dom parser for laravel 5

htmlparsingdomlaravel

提问by Jensej

where I can find simple html dom parser for laravel 5? I'm looking for somethink like this: http://simplehtmldom.sourceforge.net/manual.htm

在哪里可以找到适用于 Laravel 5 的简单 html dom 解析器?我正在寻找这样的想法:http: //simplehtmldom.sourceforge.net/manual.htm

回答by Limon Monte

I recommend FriendsOfPHP/Goutte, it's deservedly one of the most popular PHP crawlers on GitHub.

我推荐FriendsOfPHP/Goutte,它当之无愧是 GitHub 上最受欢迎的 PHP 爬虫之一。

Controller

控制器

$crawler->filter('a[class="o_title"][href]')->each(function ($node) {
    $hrefs[] = $node->attr('href'); 
});

return view('some-template', ['hrefs' => $hrefs]);

View

看法

@foreach ($hrefs as $href)
    {{ $href }}
@endforeach

In your case it will be:

在您的情况下,它将是:

$crawler = $client->request(
    'GET', 
    'http://www.oglaszamy24.pl/ogloszenia/nieruchomosci/domy/?std=1&results=100000'
);
$text = $crawler->filter('.resultpages_current')->text();
$numPages = intval(preg_replace('/[^0-9]/', '', $text));