FriendsOfPHP / Goutte

Goutte, a simple PHP Web Scraper
MIT License
9.26k stars 1.01k forks source link

Selecting a input tag and clicking it if it doesn't have an href #434

Open cverster opened 3 years ago

cverster commented 3 years ago

Hi there!

I'm pretty new to Goutte, and I've run into my first challenge already. I'm trying to navigate a .aspx site and I'm finding it hard to select the elements that I need and click them. The website starts out with an "Accept terms and conditions" page, basically one big form, and it has a button that I want to click with the following html:

<input type="submit" name="butAccept" value="I Accept the Conditions of Use" id="butAccept" accesskey="A" tabindex="1" title="Click this button to accept the Conditions of Use">

Next, a page appears where I want to input a number into an input field, and then click a submit button with a specific id / name. Here is the input field:

<input name="txtRequiredNumber" type="text" maxlength="13" id="txtRequiredNumber" accesskey="N" title="Enter Number or Identity Number here." style="width:182px;">

and here is the submit button:

<input type="submit" name="butFind" value="Find" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;butFind&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="butFind" accesskey="F" title="Click this button to find the required record" style="width:70px;">

I'm finding that something like the following is not working:

$client = new Client;
$crawler = $client->request('GET', 'https://www.sanc.co.za/eRegister.aspx');
$link = $crawler->filter('butAccept')->link();
$crawler = $client->click($link);

Can anyone tell me how to handle a page like this?