title: Auto Login using Python to my local internet page
body: <p>I have cable internet which requires me to login though a web page. It's annoying how it resets every day at 8 and 12am. I wanted to write a python script which will automate the login process. I've read many StackOverflow solutions so far, nothing has worked. I have tried <a href="https://stackoverflow.com/a/12103969/4915488">Requests</a>, <a href="https://stackoverflow.com/questions/2910221/how-can-i-login-to-a-website-with-python">Twill</a>, <a href="https://www.quora.com/What-is-the-best-way-to-log-in-to-a-website-using-Python" rel="nofollow noreferrer">RoboBrowser</a> etc.</p>
  
  <p>Upon inspecting the page source I came across a doLogin() ajax script, which is triggered by login button. Here is the full <a href="https://pastebin.com/DnwAy62r" rel="nofollow noreferrer">page source</a>.</p>
  
  <p>following is one of my implementations which fails</p>
  
  <pre><code>import requests
  
  # Fill in your details here to be posted to the login form.
  payload = {
      'action': 'http://10.10.0.1/login',
      'actualusername': 'username',
      'actualpassword': 'password'
  }
  
  # Use 'with' to ensure the session context is closed after use.
  with requests.Session() as s:
      p = s.post("http://103.251.83.134/captiveportal/Default.aspx", data=payload)
      # print the html returned or something more intelligent to see if it's a successful login page.
      print p.text
  
      # An authorised request.
      #r = s.get('http://www.google.com')
      #print r.text
  </code></pre>
  
  <h1>EDIT: Solution</h1>
  
  <p>I used Selenium WebDriver to fix this. Check answer.</p>