2

I'm using https://github.com/dweidner/laravel-goutte crawler and trying to login to https://home.openweathermap.org/users/sign_in but response I'm getting is only: enter image description here

Error message:

The change you wanted was rejected.

Maybe you tried to change something you didn't have access to.

If you are the application owner check the logs for more information.

Code:

  $client = new Client();

  $crawler = $client->request('GET', 'https://home.openweathermap.org/users/sign_in');

  $form = $crawler->filter('#new_user')->form();
  $crawler = $client->submit($form, array('user[email]' => 'email', 'user[password]' => 'password'));

  echo $crawler->html();

Is it possible to login and scrape openweathermap page? If so how could I do that?

Thank you for your help.

Fix for this problem:

$client = new Client();

$crawler = $client->request('GET', 'https://home.openweathermap.org/users/sign_in');

$form = $crawler->filter('#new_user')->form();
$token = $crawler->filter('meta[name="csrf-token"]')->first()->attr('content');

$crawler = $client->submit($form, [
  'user[email]' => 'email',
  'user[password]' => 'password',
  'authenticity_token' => $token]);

echo $crawler->html();
  • Generally, it is better to just copy/paste error messages into your Q. In any case you shouldn't expect readers to go to external sites to understand your Q. If there was something important in the linked image that is not text, then you should embed the image in the Q using the Image tool in the edit tool box menu. Good luck. – shellter Oct 11 '17 at 03:16
  • hi Giedrius Stack, you might be interested on what `$client->submit()` do, since you will need to check whether it post the `authenticity_token` or not. – Bagus Tesa Oct 11 '17 at 06:13
  • @BagusTesa ... yeh that was the case now it works fine, thanks – Giedrius Stack Oct 11 '17 at 06:23
  • wait, what, so.. what did you change to make it work? i'm curious, since it seems the [`Symfony\Component\DomCrawler\Form`](https://github.com/symfony/dom-crawler/blob/master/Form.php#L96-L98) already handle that hidden field.. – Bagus Tesa Oct 11 '17 at 06:26

0 Answers0