我希望自动登录到phpBB网站。
所以我能够自动导航,用户名,密码甚至复选框。但是,我需要能够“单击”登录按钮。
以下是与“登录”按钮相关的站点代码:
<form action="http://www.somethingorother.com/login.php" method="POST" onsubmit="return validateOwnerLogin()" >
<table width="100%" cellpadding="5" cellspacing="0" border="0">
<tr>
<td width="30%" align="right" valign="top">
Login
</td>
<td width="70%" align="left" valign="top">
<input type="text" size="45" name="login" maxlength="50">
</td>
</tr>
<tr>
<td width="30%" align="right" valign="top">
Password (min 4 characters)
</td>
<td width="70%" align="left" valign="top">
<input type="password" size="45" name="password" maxlength="50">
</td>
</tr>
<tr>
<td width="30%" align="right" valign="top">
<input type="checkbox" name="terms_read" value="yes">
</td>
<td width="70%" align="left" valign="top">
By using this Login window, I agree to the Terms and Conditions.
</td>
</tr>
<tr>
<td width="30%" align="right" valign="top">
</td>
<td width="70%" align="left" valign="top">
<input type="submit" value="Login">
</td>
</tr>
从挖掘中我已经发现“登录”值可能是这里的问题,因为有多个。我尝试过.click()和.submit()尝试。
总是以:
结束You cannot call a method on a null-valued expression.
At line:12 char:1
+ $submitButton = $doc.getElementById('Login')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
我甚至可以用IE和提示这样做吗?或者是否有Invoke-WebRequest的替代方案?
答案 0 :(得分:1)
关键是html上的这个块:
</td>
<td width="70%" align="left" valign="top">
<input type="submit" value="Login">
</td>
</tr>
显然没有“ID”可供使用。但是,利用 .getElementsByTagName 我可以指定这个。
以下是我用来“点击”登录按钮的代码。
$Link=$ie.Document.getElementsByTagName("input") | where-object {$_.type -eq "submit"}
$Link.click()