gpt4 book ai didi

javascript - Python/请求 : Log In to Website Javascript

转载 作者:行者123 更新时间:2023-11-29 23:31:17 25 4
gpt4 key购买 nike

我正在尝试创建一个脚本来登录网站,但我很难让它在这个特定页面上运行。仅供引用,我对使用 python 请求很陌生。我可以在 selenium 中执行该功能,我可以使用其他网站上的请求来登录,但我相信这个网站使用的是 javascript,这很可能是我的问题。

代码:

while (FoundItem == "Nope"):


SignIn = "https://www.bestbuy.ca/profile/signin.aspx"


Email = "ctl00$CP$SignInUC1$UserNameContainer$txtUserName"
Password= "ctl00$CP$SignInUC1$PasswordContainer$txtPassword"

payload = {
'ctl00$CP$SignInUC1$UserNameContainer$txtUserName': 'MYEMAIL',
'ctl00$CP$SignInUC1$PasswordContainer$txtPassword': 'MYPASSWORD'
}

with requests.Session() as s:
p = s.post(SignIn, data=payload)

print(p.content)

站点登录表单中的 HTML:

<div class="chkout-fieldbox std-half-cln signinblock checkout-form" id="sign-in">
<div class="std-half-cln-wrapper">

<h2 class="module-title"><span id="ctl00_CP_SignInUC1_lblSinginHeader">Returning Customer?</span></h2>
<p class="std-bottomspace">Please sign in to Your Account</p>




<fieldset class="checkout-fieldset">
<legend>Sign in for fast and easy checkout</legend>
<ul class="clearfix">
<li class="large">
<label for="ctl00_CP_SignInUC1_UserNameContainer_txtUserName">Email Address</label>


<span id="ctl00_CP_SignInUC1_UserNameContainer"><span id="ctl00_CP_SignInUC1_UserNameContainer_proxyValidator" style="color:Red;display:none;"></span><input name="ctl00$CP$SignInUC1$UserNameContainer$txtUserName" type="email" maxlength="80" id="ctl00_CP_SignInUC1_UserNameContainer_txtUserName" tabindex="1" class="txtbox" autocomplete="off" placeholder="example@example.com" onblur="if (this.onchange!=null)this.onchange();"><span id="ctl00_CP_SignInUC1_UserNameContainer_ctl00" style="display:none;">
<img id="ctl00_CP_SignInUC1_UserNameContainer_ctl00_imgUserName" src="https://images.bbycastatic.ca/sf/images/common/pictures/warningiconsmall.gif" alt=" ">
</span></span>
</li>
<li class="large">
<label for="ctl00_CP_SignInUC1_PasswordContainer_txtPassword">Password</label>
<span id="ctl00_CP_SignInUC1_PasswordContainer"><span id="ctl00_CP_SignInUC1_PasswordContainer_proxyValidator" style="color:Red;display:none;"></span><input name="ctl00$CP$SignInUC1$PasswordContainer$txtPassword" type="password" id="ctl00_CP_SignInUC1_PasswordContainer_txtPassword" tabindex="2" class="txtbox" autocomplete="off" onblur="if (this.onchange!=null)this.onchange();"><span id="ctl00_CP_SignInUC1_PasswordContainer_ctl00" style="display:none;">
<img id="ctl00_CP_SignInUC1_PasswordContainer_ctl00_imgPassword" src="https://images.bbycastatic.ca/sf/images/common/pictures/warningiconsmall.gif" alt=" ">
</span></span>
<span class="subtext-wrapper">
<p class="subtext-notification">
<a id="ctl00_CP_SignInUC1_lnkForgotPassword" href="javascript:__doPostBack('ctl00$CP$SignInUC1$lnkForgotPassword','')">I forgot my password</a>
</p>


</span>
</li>
</ul>
<div id="CaptchaContainer" class="clearfix btm-margin2x">



</div>


</fieldset>
<a id="ctl00_CP_SignInUC1_BtnLoginButton" tabindex="4" type="submit" class="button-left btn-primary btn btn-lock" href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$CP$SignInUC1$BtnLoginButton", "", true, "signin", "", false, true))'>Sign In</a>
</div>
</div>

最佳答案

我没有完整的答案给你,但也许我可以帮你指明方向。


首先,您是对的,正在调用 javascript。在您发布的 html 中,登录按钮是 ctl00_CP_SignInUC1_BtnLoginButton 并且它的 href 属性中隐藏了一些 javascript:

href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$CP$SignInUC1$BtnLoginButton", "", true, "signin", "", false, true))

单击该按钮时,您的浏览器会启动 postback到服务器,其中包含登录页面的状态。

不幸的是,我以前从未处理过回发。但是似乎确实有一些关于该主题的帖子。这是 one看起来很有用。

关于javascript - Python/请求 : Log In to Website Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47292464/

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