powershell:自动表单登录

迈克·斯科夫比

好的,因此我很难让我的脚本与登录页面上的HTML表单进行交互,我希望它可以访问它。

现在,该网站以一个显示“注册”或“登录”的页面开始,我已使它单击“登录”按钮,然后提示您进入表单页面,您在其中填写用户名和密码,按下登录按钮,然后您就可以从该页面上执行任何操作来访问该网页。

我的问题是,无论我如何尝试,从网络上的其他来源开始,除了进入表单页面外,它只会做其他任何事情。它既不想将用户名填入输入字段,也不想对密码字段做任何事情,而且无论我尝试了什么,它甚至都不想单击按钮输入。

我卡在上面的网页图像。

我卡在上面的网页的源代码

我只能得到该代码的屏幕截图,因为它是从网页的源代码中提取的,我无法复制任何代码。

$ie = New-Object -comobject InternetExplorer.Application
$FormElementsequestURI = 'https://itd-skp.sde.dk'

$ie.visible = $true
$ie.Silent  = $true
$ie.navigate($FormElementsequestURI)

while($ie.readystate -ne 4) {start-sleep -milliseconds 100}

$doc        = $ie.Document
$doc.links[1].click()

while($.ie.readystate -ne 4) {start-sleep -milliseconds 100}

#$ie.document.getElementsById("username").value = "[email protected]"
$ie.button.click() 


this is my script. i've tried with:
Doc.Documents.getElementsById
Doc.Documents.GetElementsByTag
$ie.docuements.GetElementsByTag
$ie.documents.getElementsById

这些都不起作用,老实说我很茫然。我放弃了表单输入字段,并尝试至少使它单击,但似乎没有任何效果,因此我已向stackoverflow之神寻求指导。

In the end, my goal is, that i want it to, after it has accessed the HTML login form, then it should fill in the respective input fields with my username and password, then click the login submit button to login. I have been struggling with this for the past 4 days without success and i am close to giving up, honestly.

Help me, benevolent gods!

Mike skovby

I found the answer through 3 different posts on other forums, which ended up solving my problem.

The first was for the input fields, which was:

$form = $ie.document.forms[0]
$inputs = $form.GetElementsByTagName("input")
($inputs | where {$_.name -eq "username"}).value = $user
($inputs | where {$_.name -eq "password"}).value = $pass

this inputs the information given in the variables for $user and $pass into the respective input fields.

and for the code for the button click, the solution was:

$button = $ie.document.getElementsByTagName("button")[0]
$button.click()

All this combined was enough to in the end, fix my problem and granted me access unto the site.

希望我能很好地解释一下,如果有人遇到和我一样的问题,他/她将从中得到一些帮助

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章