gpt4 book ai didi

symfony - Goutte Scrape 登录到 https 安全网站

转载 作者:太空宇宙 更新时间:2023-11-03 12:58:02 25 4
gpt4 key购买 nike

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

cURL 错误 60:SSL 证书问题:无法获取本地颁发者证书
500 内部服务器错误 - RequestException
1 个链接异常: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 登录,这样抓取我需要的数据会更容易。请问有什么帮助或建议吗?谢谢!

最佳答案

在代码中添加以下内容修复错误(curl 配置):

    // 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

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

关于 node list empty 的先前错误的修复是 Github 登录页面按钮实际上说的是“登录”而不是提交登录 在按钮上。不幸的是,Goutte api 不清楚 $form = $crawler->selectButton('Sign in')->form(); 是否引用 html name 属性或按钮的实际纯文本。显然是纯文本;有点困惑。因此,在对记录不完整的 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();

关于symfony - Goutte Scrape 登录到 https 安全网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29092197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com