Guest User

Untitled

a guest
Apr 7th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import requests
  2. import lxml.html
  3. from bs4 import BeautifulSoup
  4.  
  5. # URL of webpage
  6. login_url = "https://cas.tamu.edu/cas/login?service=https://howdy.tamu.edu/uPortal/Login&renew=true"
  7. username = # my username
  8. password = # my password
  9.  
  10. # create a session to store cookies
  11. sesh = requests.session()
  12.  
  13. params = {'service': howdy}
  14. # gets the URL and converts the text of the HTML code
  15. req = sesh.get(login_url, params=params)
  16. html_content = req.text
  17.  
  18. print html_content
  19.  
  20. # parsing the page for hidden inputs
  21. login_html = lxml.html.fromstring(html_content)
  22. hidden_inputs = login_html.xpath(r'//form//input[@type="hidden"]')
  23. user_form = {x.attrib["name"]: x.attrib["value"] for x in hidden_inputs}
  24. print(user_form)
  25.  
  26. user_form["username"] = username
  27. user_response = sesh.post(login_url, data=user_form)
  28.  
  29. print user_response.url
  30.  
  31. # same thing for the password page
  32. pass_form = {x.attrib["name"]: x.attrib["value"] for x in hidden_inputs}
  33. print(pass_form)
  34.  
  35. pass_form["password"] = password
  36. pass_response = sesh.post(user_response.url, data=pass_form)
  37.  
  38. print pass_response.url
Add Comment
Please, Sign In to add comment