我在PHP中使用DOMCrawler。我有下面的HTML。 我需要能够选择“Text1”选项,然后提交表单。我有以下代码,但我似乎无法使其工作......我做错了什么?
use Goutte\Client;
$client = new Client();
$crawler = $client->request('GET', 'http://myURL');
$form = $crawler->selectButton('Text1')->form();
$crawler2 = $client->submit($form);
这是HTML:
<form action="something.php" name="frmOpcion" id="frmOpcion" method="post" enctype="multipart/form-data">
<select name="cmbOpcion" id="cmbOpcion" class="textoCmb">
<option value="a">Text1</option>
<option selected="selected" value="b">Text2</option>
</select>
<input type="image" name="imgOpcion" id="imgOpcion" alt="Send" title="Send" src="goTo.gif">
</form>
答案 0 :(得分:0)
documentation给出了这个例子:
// Select an option or a radio
$form['country']->select('France');
要使示例适应您的情况,请先选择表单。请注意selectButton()
用于按钮和输入,而不是选择控件:
$form = $crawler->selectButton('imgOpcion');
接下来,设置select:
的值$form->select('Text1');
最后,提交表格:
$client->submit($form)