2

I am trying to create a script to log into a website but I am struggling to have it work on this particular page. FYI I'm rather new to using python requests. I can perform the function in selenium and I can use requests on other sites to log in but I believe this one is using javascript and that is more than likely my issue.

Code:

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 from the site log in form:

<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>

Aiden
  • 309
  • 2
  • 16

1 Answers1

1

I don't have a complete answer for you, but maybe I can help with direction.


First off, you're correct, javascript is being called. In the html you posted, the login button is ctl00_CP_SignInUC1_BtnLoginButton and it has some javascript hidden in its href property:

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

When the button is clicked, your browser launches a postback to the server, which contains the state of the login page.

Unfortunately, I've never dealt with postback before. But there does seems to be a few posts on the topic. Here's one that looks useful.

Alter
  • 3,332
  • 4
  • 31
  • 56