forked from michaelkitas/Python-Selenium-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
save-cookies.py
42 lines (30 loc) · 1.44 KB
/
save-cookies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pickle
import undetected_chromedriver as uc
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
if __name__ == '__main__':
email = "YOUR_EMAIL"
password = "YOUR_PASSWORD"
options = webdriver.ChromeOptions()
#options.add_argument('proxy-server=106.122.8.54:3128')
#options.add_argument(r'--user-data-dir=C:\Users\suppo\AppData\Local\Google\Chrome\User Data\Default')
browser = uc.Chrome(
options=options,
)
browser.get('https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&hl=en&flowName=GlifWebSignIn&flowEntry=ServiceLogin')
browser.find_element(By.ID, 'identifierId').send_keys(email)
browser.find_element(
By.CSS_SELECTOR, '#identifierNext > div > button > span').click()
password_selector = "#password > div.aCsJod.oJeWuf > div > div.Xb9hP > input"
WebDriverWait(browser, 10).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, password_selector)))
browser.find_element(
By.CSS_SELECTOR, password_selector).send_keys(password)
browser.find_element(
By.CSS_SELECTOR, '#passwordNext > div > button > span').click()
time.sleep(5)
cookies = browser.get_cookies()
pickle.dump(cookies, open("cookies.pkl", "wb"))