Oli*_*ton 2 php web-scraping goutte
我试图刮掉以下内容,我基本上想要文本和链接,我正在使用Goutte和PHP.我可以使用以下代码获得文本,但我无法获得href值.任何帮助都会很棒.
$crawler->filter('#most-popular > div > ol > li > a')->each(function ($node) {
var_dump($node->getAttribute('href'));
});
<li class="first-child ol1">
<a href="http://www.bbc.co.uk/news/uk-england-south-yorkshire-31895703" class="story">
<span class="livestats-icon livestats-1">1: </span>MP claims £17 poppy wreath expenses</a>
</li>
Run Code Online (Sandbox Code Playgroud)
Bur*_*rak 12
getAttribute()被实现为attr()所述内Crawler类.
$crawler->filter('#most-popular > div.panel.open > ol > li.first-child.ol1 > a')->each(function ($node) {
var_dump($node->attr('href'));
});
Run Code Online (Sandbox Code Playgroud)
波纹管代码将解决此问题.
$crawler->filter('#most-popular > div.panel.open > ol > li.first-child.ol1 > a')->each(function ($node) {
$href = $node->extract(array('href'));
var_dump($href[0]);
});
Run Code Online (Sandbox Code Playgroud)