php - Crawler + Guzzle: Accessing to form -
i using php guzzle client grab website, , process symfony 2.1 crawler
i trying access form....for example test form here http://de.selfhtml.org/javascript/objekte/anzeige/forms_method.htm
$url = 'http://de.selfhtml.org/javascript/objekte/anzeige/forms_method.htm'; $client = new client($url); $request = $client->get(); $request->getcurloptions()->set(curlopt_ssl_verifyhost, false); $request->getcurloptions()->set(curlopt_ssl_verifypeer, false); $response = $request->send(); $body = $response->getbody(true); $crawler = new crawler($body); $filter = $crawler->selectbutton('submit')->form(); var_dump($filter);die();
but exception:
the current node list empty.
so kind of lost, on how access form
try using goutte, screen scraping , web crawling library build on top of tools using (guzzle, symfony2 crawler). see github repo more info.
your code using goutte
<?php use goutte\client; $url = 'http://de.selfhtml.org/javascript/objekte/anzeige/forms_method.htm'; $client = new client(); $crawler = $client->request('get', $url); $form = $crawler->selectbutton('submit')->form(); $crawler = $client->submit($form, array( 'username' => 'myuser', // assuming submitting login form 'password' => 'p@s5' )); var_dump($crawler->count()); echo $crawler->html(); echo $crawler->text();
if need setup curl options can way:
<?php $url = 'http://de.selfhtml.org/javascript/objekte/anzeige/forms_method.htm'; $client = new client(); $guzzle = $client->getclient(); $guzzle->setconfig( array( 'curl.curlopt_ssl_verifyhost' => false, 'curl.curlopt_ssl_verifypeer' => false, )); $client->setclient($guzzle); // ...
update:
when using domcrawler times same error. of time because i'm not selecting correct element in page, or because doesn't exist. try instead of using:
$crawler->selectbutton('submit')->form();
do following:
$form = $crawler->filter('#signin_button')->form();
where using filter method element id if has 1 '#signin_button'
or class '.signin_button'
. filter method requires the cssselector component.
also debug form printing out html (echo $crawler->html();
) , ensuring on right page.
Comments
Post a Comment