使用Goutte和PHP抓取列表以获取href的问题
我试图刮以下,我基本上想要的文本和链接,我与PHP使用。我可以使用以下代码获得文本,但无法获得href值。任何帮助都将是惊人的使用Goutte和PHP抓取列表以获取href的问题,php,web-scraping,goutte,Php,Web Scraping,Goutte,我试图刮以下,我基本上想要的文本和链接,我与PHP使用。我可以使用以下代码获得文本,但无法获得href值。任何帮助都将是惊人的 $crawler->filter('#most-popular > div > ol > li > a')->each(function ($node) { var_dump($node->getAttribute('href')); }); <li class="first-child ol1">
$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>
$crawler->filter('#最流行的>div>ol>li>a')->每个(函数($node){
变量转储($node->getAttribute('href');
});
以下代码将解决此问题
$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]);
});
在类中实现
谢谢@halfer的编辑
$crawler->filter('#most-popular > div.panel.open > ol > li.first-child.ol1 > a')->each(function ($node) {
var_dump($node->attr('href'));
});