Goutte: How to submit a form button without value?

2.1k views Asked by At

On Amazon Create Wish List Link which popup a form. the form contains a submit button in following fashion:

<span class="a-button-inner"><input data-action="reg-create-submit" data-reg-create-submit="{&quot;sid&quot;:&quot;192-7611799-5529931&quot;}" class="a-button-input a-declarative" type="submit" aria-labelledby="a-autoid-162-announce"><span class="a-button-text" aria-hidden="true" id="a-autoid-162-announce">
    Create a Wish List
</span></span>

I am using following code but it is not fetching form:

require_once 'goutte.phar';
error_reporting(E_ALL);
use Goutte\Client;

$crawler = $client->request('GET',$url);
$status_code = $client->getResponse()->getStatus();
$form = $crawler->selectButton('Sign in')->form();
$crawler = $client->submit($form, array('email' => '[email protected]', 'password' => 'amazonpasswd'));
//Create a Wish List
$crawler = $client->request('GET',"http://www.amazon.com/gp/registry/wishlist/ref=nav_wishlist_create?ie=UTF8&triggerElementID=createList");
sleep(5);
$form = $crawler->selectButton('
        Create a Wish List
      ')->form();

print_r($form); //It returns Nothing

The issue is probably that selectButton() matches exact text which in my case is not there. Please help

1

There are 1 answers

0
aDoN On

Well let's get this straight. What you need is to reach your target "form" element, for this matter, you don't strictly need to use the "selectButton" function you can get this element with just an XPath expression.

I think the web structure has changed since you posted this, because now the "Create a Wish List" button apparently has a value "createNew" but in order to crawl websites with a button with no value you can do this:

require_once 'goutte.phar';

use Goutte\Client;

$client = new Client();

$crawler = $client->request('GET', 'http://www.amazon.com/gp/registry/wishlist/ref=nav_wishlist_create?ie=UTF8&triggerElementID=createList');

$form = $crawler->filterXPath('//h1[@class="a-nowrap"]/form')->form();

print_r ($form);

That way you can access a form without the selectButton function and you can input that form the normal way:

$crawler = $client->submit($form, array('input_name1' => 'value1', 'input_name2' => 'value2'));

Hope this helps.