PowerShell点击表单提交URL不正确

时间:2018-11-03 19:12:40

标签: powershell

Tl:dr:当action参数不包含完整域名时,我需要能够使用PowerShell提交HTML表单。

我要使用PowerShell单击以下形式的votea按钮:

<form action="submit.aspx#submittop" method="post" id="submit-control-form" name="form1">
    <input type="hidden" name="add_id" value="123456789">
    <input type="hidden" name="nextfive" value="<form action="submit.aspx#submittop" method="post" id="submit-control-form" name="form1">
                            <input type="hidden" name="add_id" value="123456789">
                            <input type="hidden" name="nextfive" value="123456789,123456789,123456789,123456789,123456789,123456789,70974215,123456789,123456789,123456789,69717999,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,91092904,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789,123456789">
                            <input type="hidden" name="p_Id" value="123456789">
                            <input type="hidden" name="u_Id" value="123456789">
                            <input type="hidden" name="sp_Id" value="1234">
                            <input type="hidden" name="lv_dt" value="04/01/2016 08:57:23 AM">
                            <input type="hidden" name="username_vote" value="someusername">
                            <input type="hidden" name="h" value="0">
                            <input type="hidden" name="s" value="0">

                            <button type="submit" class="submit-no-button" id="submit-button-no-var" name="votec" value="3">No</button>

                            <button type="submit" class="submit-yes-button" id="submit-button-yes-var" name="votea" value="1">Yes</button>                                  



                        </form>">
    <input type="hidden" name="p_Id" value="123456789">
    <input type="hidden" name="u_Id" value="123456789">
    <input type="hidden" name="sp_Id" value="1234">
    <input type="hidden" name="lv_dt" value="04/01/2016 08:57:23 AM">
    <input type="hidden" name="username_vote" value="someusername">
    <input type="hidden" name="h" value="0">
    <input type="hidden" name="s" value="0">  



</form>

这是我的源代码:

function Invoke-DomainLogin([Parameter(Mandatory=$True)][System.Management.Automation.PSCredential]$Credential){

    $URL = "example.com"

    $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credential.Password)
    $ptPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

    $LoginBody = @{

        username = $Credential.UserName
        password = $ptPassword

    }


    Do {

        $Login = Invoke-WebRequest $URL/viewrespond.aspx -SessionVariable Domain -Method Post -Body $LoginBody

        if ($Login.Content -like "*Your email or password were entered incorrectly*"){

            Throw "Credentials incorrect"

        }

        $submit = Invoke-WebRequest ($mmURL = "$URL/submit.aspx#submittop") -WebSession $Domain -Method Post


        $Click = $submit.ParsedHtml.body.getElementsByTagName("button")|Where-Object {$_.name -eq "votea"}

        $Click.click()

        $Obj = New-Object PSObject

        $Obj|Add-Member -MemberType NoteProperty -Name Username -Value ($submit.Forms|Where-Object Id -eq "submit-control-form").Fields.username_vote
        $Obj|Add-Member -MemberType NoteProperty -Name Link     -Value ("{0}/{1}" -f $URL,($submit.Links|Where-Object innerHtml -Eq "View Profile").href)

        $Obj

        Start-Sleep -Seconds 1

    }
    while($fakestring -ne "fakestring")


}

Invoke-DomainLogin $Cred

当我执行$Click.click()时,除非将IE设置为默认浏览器,否则会出现一个打开文件的对话框,询问我要使用哪个应用程序(什么?!)-因此,我将设置IE的默认浏览器,我发现表单操作URL缺少域名,因此浏览器中的URL将是/submit.aspx#submittop并且不包含URL,因为表单操作URL没有完整的域名指定。

我无权以任何方式更改表单,如何让PowerShell操纵表单中的操作网址,使其为example.com/submit.aspx#submittop

0 个答案:

没有答案