0

Having issues using python to login to web portal. I've tried using suggestions from other posts

How can I login to a website with Python?

I've tried using twill (which failed to install because I'm running Python 3.6) - if anyone has suggestions how I can install it please advise

I've also tried using:

import requests
url = 'http://example.com/userinfo.php'
values = {'username': 'user',
          'password': 'pass'}

r = requests.post(url, data=values)
print(r.content)

with no luck.

The login page has the following html

<form id="form" method="post" action="/" style="padding-left:20px;" class="form-horizontal">
                    <div class="control-group">
                        <label class="control-label" for="username">User Name:</label>
                        <div class="controls">
                            <input id="username" type="text" placeholder="User Name" autocomplete="off" autocorrect="off" autocapitalize="off">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="ba_password2">Password:</label>
                        <div class="controls">
                            <input id="ba_password2" type="password" placeholder="Password">
                            <input type="hidden" id="ba_username" name="ba_username">
                            <input type="hidden" name="ba_password">
                                                            <input type="hidden" name="ba_seed" value="614377365">
                            <input type="hidden" name="ba_salt" value="dgvwghgwuoyixgsrdhblkgigmtrhivbx">
                            <input type="hidden" name="ba_seedkey" value="-1647247092">
                                                        </div>
                    </div>
                    <div class="control-group">
                        <div class="controls">
                            <label class="checkbox">
                                <input type="checkbox" name="rememberMe"> Remember me on this computer
                            </label>
                            <button id="ba_loginbut" type="submit" class="btn">Login</button>
                        </div>
                    </div>
                    <div class="msgHolder">
                                                    <div id="login-error-box" class="errormsg" style="display:none;">
                            <img src="/images/err.png"/>
                            <div id="login-error-msg"></div>
                        </div>
                        <div id="capslock" class="errormsg" style="display:none;">
                            <img src="/images/warn.png"/>
                            Caps lock is on.
                        </div>
                    </div>
                </form>

I hope someone can help. Thanks

2 Answers2

0

Consider using libraries like webbot which even handle dynamically changing class and id for the webpage elements.

Natesh bhat
  • 12,274
  • 10
  • 84
  • 125
0

With a Python code must looks like this:

#Open Firefox browser
driver = webdriver.Firefox()
#Enter email
elem = driver.find_element_by_id("username")
elem.clear()
elem.send_keys("email")
#Enter password
elem = driver.find_element_by_id("ba_password2")
elem.clear()
elem.send_keys("pass")
#Click button
elem = driver.find_element_by_id("ba_loginbut")
elem.click()
Vilius
  • 91
  • 1
  • 3
  • 9