简体   繁体   中英

Goutte: How to submit a form button without value?

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' => 'amazon@gmail.com', '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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM