Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Goutte和PHP抓取列表以获取href的问题_Php_Web Scraping_Goutte - Fatal编程技术网

使用Goutte和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">

我试图刮以下,我基本上想要的文本和链接,我与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>
$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'));
    });