Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from selenium.webdriver.firefox.options import Options
- import time
- import imaplib
- from bs4 import BeautifulSoup
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- from selenium.webdriver.common.by import By
- def getCode(username, password):
- imap_ssl_host = 'imap.gmail.com'
- imap_ssl_port = 993
- server = imaplib.IMAP4_SSL(imap_ssl_host, imap_ssl_port)
- server.login(username, password)
- server.select('Inbox')
- status, data = server.search(None, 'ALL')
- lel = (data[0].split())[-1]
- status,data = server.fetch(lel,'(RFC822)')
- email_msg = data[0][1]
- zz = (email_msg.decode('utf-8')).split('</style>')
- lol = zz[1] + '</body>'
- soup = BeautifulSoup(lol, "lxml")
- code = ((soup.findAll("p"))[0].text.split(": "))[1]
- server.close()
- server.logout()
- return code
- def main():
- options = Options()
- gmail_username = ''
- gmail_password = ''
- options.headless = True
- driver = webdriver.Firefox(options=options)
- driver.get('https://www.twitch.tv/login')
- username = driver.find_element_by_id("login-username")
- password = driver.find_element_by_id("password-input")
- username.send_keys("")
- password.send_keys("")
- driver.find_element_by_xpath('//button[@data-a-target="passport-login-button"]').click()
- #WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.XPATH, '//input[@data-a-target="tw-input"]'))) #a me da problemi, quindi uso un timer
- time.sleep(15) #15 secondi sono un po' tanti ma almeno sono sicuro che si sia aggiornato + sia arrivato il codice
- lmao = driver.find_element_by_xpath('//input[@data-a-target="tw-input"]')
- code = getCode(gmail_username, gmail_password)
- lmao.send_keys(code)
- WebDriverWait(driver, 10).until(EC.url_changes(driver.current_url))
- driver.get('https://www.twitch.tv/Yassuo')
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement