Advertisement
Guest User

Untitled

a guest
Oct 11th, 2018
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import requests
  2. from lxml import html
  3.  
  4. LOGIN_URL = "https://cas.sfu.ca/cas/login?service=https://my.sfu.ca/mysfu/auth&app=mySFU"
  5. URL = "https://my.sfu.ca/mysfu/"
  6.  
  7. def main():
  8. session_requests = requests.session()
  9.  
  10. # Get login csrf token
  11. result = session_requests.get(LOGIN_URL)
  12. tree = html.fromstring(result.text)
  13. authenticity_token = list(set(tree.xpath("//input[@name='lt']/@value")))[0]
  14.  
  15. # Create payload
  16. payload = {
  17. "username": "v*****",
  18. "password": "Y*****",
  19. "lt": "LT-447-A4KGjbl5jVX4ZvRwNGRIL0xodSHcJY"
  20. }
  21.  
  22. # Perform login
  23. result = session_requests.post(LOGIN_URL, data = payload, headers = dict(referer = LOGIN_URL))
  24.  
  25. # Scrape url
  26. result = session_requests.get(URL, headers = dict(referer = URL))
  27. tree = html.fromstring(result.content)
  28. bucket_names = tree.xpath("//div[@class='repo-list--repo']/a/text()")
  29.  
  30. print(bucket_names)
  31.  
  32. if __name__ == '__main__':
  33. main()
  34.  
  35. ####################################################################
  36. Username:
  37. <input id="username" name="username" tabindex="1" class="text" onfocus="GaveFocus(this)" type="text" value="" autocomplete="false"/>
  38. Password:
  39. <input id="password" name="password" tabindex="2" onkeypress="capLock(event)" class="text" onfocus="GaveFocus(this)" type="password" value="" autocomplete="off"/>
  40. Token:
  41. <input type="hidden" name="lt" value="LT-293557-0lx4PsiambnCMcpbaDLpbwzPxVEFh4" />
  42. Login URL
  43. https://cas.sfu.ca/cas/login?service=https://my.sfu.ca/mysfu/auth&app=mySFU
  44. Desired URL
  45. https://my.sfu.ca/mysfu/
  46. Fields submitted to
  47. /cas/login;jsessionid=003D1C4D4DC4F4D4E65AEB270D897C94.cas-ap2?service=https://my.sfu.ca/mysfu/auth&amp;app=mySFU
  48. Logins managed by
  49. http://www.ja-sig.org/cas/
  50.  
  51. ############################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement