Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. def get_twitch_auth_tokens(fb_uname, fb_pword):
  2.  
  3. driver = webdriver.PhantomJS()
  4. driver.get("https://www.twitch.tv/login")
  5.  
  6. # log in via facebook
  7. driver.find_element_by_xpath("//button[@class='fb_button button']").click()
  8. driver.switch_to_window(driver.window_handles[1]) # switch to fb popup
  9. driver.find_element_by_xpath("//input[@id='email']").send_keys(fb_uname)
  10. driver.find_element_by_xpath("//input[@id='pass']").send_keys(fb_pword)
  11. driver.find_element_by_xpath("//input[@type='submit']").click()
  12. time.sleep(5) # gotta wait for this to properly log in
  13. driver.switch_to_window(driver.window_handles[0]) # switch back
  14.  
  15. #
  16. driver.get("https://www.twitch.tv/kripparian")
  17.  
  18. # save the cookies of interest
  19. twitch_persistent = ""
  20. twitch_api_token = ""
  21. cookies = driver.get_cookies()
  22. for cookie in cookies:
  23. if cookie['name'] == "persistent":
  24. twitch_persistent = cookie['value']
  25. if cookie['name'] == "api_token":
  26. twitch_api_token = cookie['value']
  27. driver.quit()
  28.  
  29. return twitch_api_token, twitch_persistent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement