Php GOUTE返回错误的url进行多个url刮取

Php GOUTE返回错误的url进行多个url刮取,php,goutte,domcrawler,Php,Goutte,Domcrawler,我正在使用。 在while循环中单击分页链接时,我总是得到错误的url 对象上的selectLink返回第一个while循环的正确url。看起来第二个循环为选择链接返回了错误的值 这是代码 public function __construct(Goutte\Client $client){ $this->client = $client; } public function parse(){ $url = "https://www.nextag.com/Arts-E

我正在使用。 在while循环中单击分页链接时,我总是得到错误的url

对象上的selectLink返回第一个while循环的正确url。看起来第二个循环为选择链接返回了错误的值

这是代码

public function __construct(Goutte\Client $client){

    $this->client = $client;
}

public function parse(){

    $url = "https://www.nextag.com/Arts-Entertainment--zz2702147z0z1zB6c4z5---html";

    // crawl through first page
    $crawler    = $this->client->request('GET', $url);

    // first page pagination links
    $links      = $this->paginationCrawler($crawler);

    $linkBatch  = array(); 

    // get all pagination links and check if the next 10 links are available 
    list($linkBatch[], $_nextPage) = $this->getPaginationLinks($links);

    // if $_nextPage == '11+/21+/etc' then crawl through all links
    while($_nextPage != 'false'){

        $link                           = $links->selectLink($_nextPage)->link();

        $crawler                        = $this->client->click($link);

        $links                          = $this->paginationCrawler($crawler);

        list($linkBatch[], $_nextPage)  = $this->getPaginationLinks($links);

    }

    dd($linkBatch);
}   

public function paginationCrawler($crawler){

    return $crawler->filter('#pagination');
}

public function getPaginationLinks($links){

    $allLinks = $links->filter('#numbers a');

    $linkNodes = $allLinks->each(function(Crawler $a) {

        return  $a->attr('href');

    });

    $lastPage = trim($links->filter('#numbers :last-child')->text());

    if (strpos($lastPage,'+') === false) {

        $lastPage = 'false';

    }

    return array($linkNodes, $lastPage);
}
以下是输出:


已解决。但是有一个工作机会。现在我发送的不是文本11+,而是url本身的链接对象。还是不明白出了什么问题,解决了。但是有一个工作机会。现在我发送的不是文本11+,而是url本身的链接对象。我还是不明白出了什么问题。