gpt4 book ai didi

powershell - Powershell invoke-webrequest过去的登录

转载 作者:行者123 更新时间:2023-12-02 23:12:13 25 4
gpt4 key购买 nike

我有一个要“浏览”的工作站点。

用这个做...

$login = Invoke-WebRequest -Uri 'http://www.privateworksite.com' -SessionVariable GetIP
$form = $login.Forms[0]
$Form.Fields['ctl00$ContentPlaceHolder1$RadTextBox7']= "*******" <-- User ID goes here
$Form.Fields['ctl00$ContentPlaceHolder1$RadButton1'] = "submit" <-- Submit button
$afterfirstclick Invoke-WebRequest -Uri 'http://www.privateworksite.com' -WebSession $GetIP -Method POST -Body $form.Fields

现在我在页面上,我需要单击出现的新按钮。我试图添加-sessionvariable $ afterfirstclick,但是我收到了可怕的PS Red行,指出您不能同时使用-WebSession和-SessionVariable。

添加的信息:
那么,如何单击$ afterfirstclick中产生的按钮?这就是我在第一次单击返回后所需要的按钮。
ctl00$ContentPlaceHolder1$RadGrid1$ctl00$ctl04$GECBtnExpandColumn  <-- a new button to create 
a drop down table with the info I need. The table is not there prior to the
clicking the button so I need to click this button.

我已经遍地开花,以前的演示/发布都是关于登录到站点的,但是之后您如何在站点中移动呢?

我试图将$ afterfirstclick喂入-WebSession中,然后关闭...
还尝试在下一个“字段”中重复整个操作以单击按钮,这只会导致新站点而不是当前站点的“延续”。

然后去哪儿?

噢,URL永不更改,因此我无法提交VIA URL。

最佳答案

确定找到解决方案!我需要将$afterfirstclick输入到下一个invoke-webrequest中。我感到很愚蠢,以至于没有那么明显。

最终结果...

$url = "http://private.com"  #<-- setup the URL
$tool = Invoke-WebRequest -Uri 'http://private.com' -UseDefaultCredentials -SessionVariable fb #<--create the site in a variable

write-host "1111111111111111" #<--just a marker to seperate the two requests so I can see the form.fields clearly
$Form = $tool.Forms[0] #<--first invoke form.fields
$Form.Fields #<--just printing them so I can see them
$Form.Fields['ctl00$ContentPlaceHolder1$RadTextBox7']= "USERID" #<--entering USERID into the form
$Form.Fields['ctl00$ContentPlaceHolder1$RadButton1'] = "submit" #<--clicking the submit button

$mainPage = Invoke-WebRequest ("$url" + $Form.Action) -WebSession $fb -Body $Form.Fields -Method Post #<--create the new page by calling the page with the fields
$mainPage.RawContent | out-file h:\response.html #<--sending it to a file so I can see the first page and second page side by side

write-host "2222222222222222" #<--just a marker to seperate the two requests so I can see the form.fields clearly
$Form2 = $mainPage.Forms[0] #<--pulling the new page form.fields NOTICE I am using the previous variable for the first invoke
$Form2.Fields #<--printing fields to take a look at what needs to be included in the next round
$Form2.Fields['ctl00$ContentPlaceHolder1$RadGrid1$ctl00$ctl04$GECBtnExpandColumn'] = "submit" #<--The newly generated button that needed to be clicked to continue

$mainPage2 = Invoke-WebRequest ("$url" + $Form2.Action) -WebSession $fb -Body $Form2.Fields -Method Post -UseDefaultCredentials #<--OK BIG ONE!! First the form.field needs to be correct as well as using the original -websession!!!
$mainPage2.RawContent | out-file h:\response1.html #<--output the second resulting page to compare

来观看第二个请求。它必须使用第一个 invoke创建新的 form.fields,但仍使用原始的 -websession变量。

不知道为什么,但是这种方式行得通,但是我在另一个站点上使用了它,使它更深入,因此它很可靠,只是不断重复链接。您甚至可以对所有已知的 foreach使用 form.fields循环。

关于powershell - Powershell invoke-webrequest过去的登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34686075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com