Advertisement
Guest User

Untitled

a guest
Oct 11th, 2018
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. import requests
  2. from lxml import html
  3.  
  4. USERNAME = "v*****2"
  5. PASSWORD = "Y*****$"
  6.  
  7. LOGIN_URL = "https://cas.sfu.ca/cas/login?service=https://my.sfu.ca/mysfu/auth&app=mySFU"
  8. URL = "https://my.sfu.ca/mysfu/"
  9.  
  10. def main():
  11. session_requests = requests.session()
  12.  
  13. # Get login csrf token
  14. result = session_requests.get(LOGIN_URL)
  15. tree = html.fromstring(result.text)
  16. authenticity_token = list(set(tree.xpath("//input[@name='lt']/@value")))[0]
  17.  
  18. # Create payload
  19. payload = {
  20. "username": "vca32",
  21. "password": "Yoseph123$",
  22. "lt": "authenticity_token"
  23. }
  24.  
  25. # Perform login
  26. result = session_requests.post(LOGIN_URL, data = payload, headers = dict(referer = LOGIN_URL))
  27.  
  28. # Scrape url
  29. result = session_requests.get(URL, headers = dict(referer = URL))
  30. tree = html.fromstring(result.content)
  31. bucket_names = tree.xpath("//div[@class='repo-list--repo']/a/text()")
  32.  
  33. print(bucket_names)
  34.  
  35. if __name__ == '__main__':
  36. main()
  37.  
  38.  
  39.  
  40. ###########################################################################################
  41. --- FORM report. Uses POST to URL "/cas/login;jsessionid=CBBFAA4DDC7F80BBEA97CDDEA70DB1B7.cas-ap2?service=https://my.sfu.ca/mysfu/auth%3Bjsessionid%3DB8647C388320FE9818FC9513EA67198B&app=mySFU"
  42. Input: NAME="username" (TEXT)
  43. Input: NAME="password" (PASSWORD)
  44. Input: NAME="lt" VALUE="LT-54033-60mrzkSibmFnkmzrTBDCl3ysusLxLf" (HIDDEN)
  45. Input: NAME="execution" VALUE="e1s1" (HIDDEN)
  46. Input: NAME="_eventId" VALUE="submit" (HIDDEN)
  47. Input: NAME="warn" VALUE="true" (CHECKBOX)
  48. Button: "Sign In" (SUBMIT)
  49. --- end of FORM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement