doubiao7267 2018-09-08 16:03
浏览 89

选择Button,然后单击goutte scraper PHP

I need click a button 'Vew more' in my page, but not is a form, is a button type "button".

My code's look:

$client = new Client();
$crawler = $client->request('GET', 'https://www.xxxx.com');
$button = $crawler->selectButton('View more');
$client->click($button);

This returns:

Catchable fatal error: Argument 1 passed to Symfony\Component\BrowserKit\Client::click() must be an instance of Symfony\Component\DomCrawler\Link, instance of Symfony\Component\DomCrawler\Crawler given, called in C:\xampp\htdocs\scrapper\index.php on line 17 and defined in C:\xampp\htdocs\scrapper\vendor\symfony\browser-kit\Client.php on line 238

Any ideas? :(

  • 写回答

1条回答 默认 最新

  • duanliaolan6178 2018-09-08 16:36
    关注

    As per the documentation:

    A selectButton() method is available on the Crawler which returns another Crawler that matches a button (input[type=submit], input[type=image], or a button) with the given text.

    Actually, that is what the error is saying: the parameter received by click() is a crawler, when it should be a Link. I'm not familiar with goutte scrapper, but have you tried with:

    $button = $crawler->selectButton('View more')->button();
    $client->click($button);
    
    评论

报告相同问题?