更新时间:2022-11-01 22:10:15
我无法按照你的问题。使用 两个 软件库的现有开发版本(以及2.1.0和2.2.0版本),dom-crawler 和 css-selector ,您提供的示例代码可以很好地考虑以下示例HTML: p>
I can not follow your problem. Using the current development versions (and also 2.1.0 and 2.2.0 versions) of the two software libraries dom-crawler and css-selector, the example code you provided works just fine considering the following example HTML:
<?php
use Symfony\Component\DomCrawler\Crawler;
// require dependencies here
$html = <<<'HTML'
<!DOCTYPE html>
<html>
<body>
<p class="message">Hello World!</p>
<p>Hello Crawler!</p>
<div id="product">
<a data-type="bla">
<img src="OK">
</a>
</div>
</body>
</html>
HTML;
$crawler = new Crawler($html);
$link = $crawler->filter('#product a[data-type="bla"]');
echo var_dump(count($link));
var_dump($link->filter('img')->attr('src'));
正如你所看到的,这正是你的代码(只是有点不同,但本质上不是)以下输出逐字:
As you can see this is exactly your code (only a little different but essentially not), which gives the following output verbatim:
int(1)
string(2) "OK"
第一个输出行是 count()
,第二个是src属性值。
The first output line is the count()
and the second is the src attribute value.
您是否运行作曲家更新?您是否仔细检查了输入?
Have you run composer update? Have you double-checked the input?