Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import lxml.html
- from bs4 import BeautifulSoup
- # URL of webpage
- login_url = "https://cas.tamu.edu/cas/login?service=https://howdy.tamu.edu/uPortal/Login&renew=true"
- username = # my username
- password = # my password
- # create a session to store cookies
- sesh = requests.session()
- params = {'service': howdy}
- # gets the URL and converts the text of the HTML code
- req = sesh.get(login_url, params=params)
- html_content = req.text
- print html_content
- # parsing the page for hidden inputs
- login_html = lxml.html.fromstring(html_content)
- hidden_inputs = login_html.xpath(r'//form//input[@type="hidden"]')
- user_form = {x.attrib["name"]: x.attrib["value"] for x in hidden_inputs}
- print(user_form)
- user_form["username"] = username
- user_response = sesh.post(login_url, data=user_form)
- print user_response.url
- # same thing for the password page
- pass_form = {x.attrib["name"]: x.attrib["value"] for x in hidden_inputs}
- print(pass_form)
- pass_form["password"] = password
- pass_response = sesh.post(user_response.url, data=pass_form)
- print pass_response.url
Add Comment
Please, Sign In to add comment