我有一个登入页面(http://**.com/def.php)页的表单代码范例:
<form action="abc.php" method="POST" name="f_action"> <input type="text" name="id"> <input type="password" name="pwd"> <input type="submit" value="OK" name="action"> </form>
我藉由PHP呼叫COM “InternetExplorer.Application”去填写表单并登入,代码如下:
<?php $Browser = new COM('InternetExplorer.Application'); $Browserhandle = $Browser->HWND; $Browser->Visible = true; $f1_url = "http://**.com/def.php"; $Browser->Navigate($f1_url); sleep(5); $Browser->Document->f_action->id->focus(); $Browser->Document->f_action->id->value = "username"; $Browser->Document->f_action->pwd->focus(); $Browser->Document->f_action->pwd->value = "password"; $Browser->Document->f_action->action->focus(); $Browser->Document->f_action->action->click(); $Browser->Quit(); ?>
里面是藉由Name属性找到要控制的元素,但若是我将范例页面的表单代码改成:
<form action="abc.php" method="POST">
将「name="f_action"」改成「无Name属性」,这样php代码要如何改写才能同样可以让COM “InternetExplorer.Application”填写表单并登入?
感谢!
开心每一天1111