So I'm trying to use Goutte to login to an https website but I get the following error:
cURL error 60: SSL certificate problem: unable to get local issuer certificate
500 Internal Server Error - RequestException
1 linked Exception: RingException
And this is the code that the creator of Goutte says to use:
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";
});
OR here's come code that Symfony recommends:
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);
The thing is that neither of them work, I get the error that I posted above. I CAN, however log in using the code written in this past question I've asked: cURL Scrape then Parse/Find Specific Content
I just want to use Symfony/Goutte to login in, so that scraping the data I need will be easier. Any help or suggestions please? Thanks!
Adding the following to the code fixes the error (curl configuration):
// 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');
But then another error occurs:
The current node list is empty.
500 Internal Server Error - InvalidArgumentException
Once again, I'm using Goutte with Symfony and default code to do a test task, such as logging into https github.
The fix for the previous error about node list empty
is that the Github login page button actually says "Sign in" and not Submit or Login on the button. Unfortunately, the Goutte api isn't clear as to if $form = $crawler->selectButton('Sign in')->form();
refers to the html name
attribute or the actual plain text of the button. It's obviously the plain text; slightly confusing. So after more research of a poorly documented api, I ended with the following code that works:
// 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();