2

因此,我尝试使用 Goutte 登录https网站,但出现以下错误:

cURL error 60: SSL certificate problem: unable to get local issuer certificate 500 Internal Server Error - RequestException 1 linked Exception: RingException

这是 Goutte 的创建者说要使用的代码:

use Goutte\Client;

$client = new Client();

$crawler = $client->request('GET', 'http://github.com/');
$crawler = $client->click($crawler->selectLink('Sign in')->link());
$form = $crawler->selectButton('Sign in')->form();
$crawler = $client->submit($form, array('login' => 'fabpot', 'password' =>     'xxxxxx'));
$crawler->filter('.flash-error')->each(function ($node) {
    print $node->text()."\n";
});

或者这里是 Symfony 推荐的代码:

use Goutte\Client;

// make a real request to an external site
$client = new Client();
$crawler = $client->request('GET', 'https://github.com/login');

// select the form and fill in some values
$form = $crawler->selectButton('Log in')->form();
$form['login'] = 'symfonyfan';
$form['password'] = 'anypass';

// submit that form
$crawler = $client->submit($form);

问题是它们都不起作用,我收到了上面发布的错误。我可以,但是使用我问过的过去问题中编写的代码登录: cURL Scrape then Parse/Find Specific Content

我只想使用 Symfony/Goutte 登录,这样抓取我需要的数据会更容易。请问有什么帮助或建议吗?谢谢!

4

1 回答 1

5

将以下内容添加到代码中可修复错误(卷曲配置):

    // make a real request to an external site
    $client = new Client();
    $client->getClient()->setDefaultOption('config/curl/'.CURLOPT_SSL_VERIFYHOST, FALSE);
    $client->getClient()->setDefaultOption('config/curl/'.CURLOPT_SSL_VERIFYPEER, FALSE);
    $crawler = $client->request('GET', 'https://github.com/login'); 

但随后发生另一个错误:

The current node list is empty.
500 Internal Server Error - InvalidArgumentException 

再一次,我使用带有 Symfony 的 Goutte 和默认代码来执行测试任务,例如登录 https github。

上一个错误的修复node list empty是 Github 登录页面按钮实际上是“登录”,而不是按钮上的提交登录。不幸的是,Goutte api 并不清楚是$form = $crawler->selectButton('Sign in')->form();指 htmlname属性还是按钮的实际纯文本。显然是纯文本;有点混乱。因此,在对文档记录不佳的 api 进行了更多研究之后,我以以下有效代码结束:

// make a real request to an external site
$client = new Client();
$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_SSL_VERIFYHOST, FALSE);
$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_SSL_VERIFYPEER, FALSE);
$crawler = $client->request('GET', 'https://github.com/login');

// select the form and fill in some values
$form = $crawler->selectButton('Sign in')->form();
$form['login'] = 'symfonyfan';
$form['password'] = 'anypass';

// submit that form
$crawler = $client->submit($form);
echo $crawler->html();
于 2015-03-17T17:13:10.947 回答