Ale*_*Kim 2 php web-crawler laravel
使用:https : //github.com/FriendsOfPHP/Goutte。我想使用以下代码从网站解析单个值:
$client = new Client();
$crawler = $client->request('GET', 'https://mig.kz');
$crawler->filter('.buy')->eq(0)->each(function ($node) {
echo $node->text();
});
Run Code Online (Sandbox Code Playgroud)
我可以使用 获得单个值each(),但是如果没有每个值,这可能吗?如何将第一个匹配值存储在变量中,然后再重用它?
我想这应该做:
$crawler->filter('.buy')->first();
Run Code Online (Sandbox Code Playgroud)
参考:https : //symfony.com/doc/current/components/dom_crawler.html#node-traversing
来自:https : //github.com/FriendsOfPHP/Goutte#more-information
来源:https : //github.com/FriendsOfPHP/Goutte#technical-information