-
Notifications
You must be signed in to change notification settings - Fork 0
/
setCookies.py
32 lines (27 loc) · 994 Bytes
/
setCookies.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
from selenium import webdriver
from selenium.webdriver.edge.options import Options
import time
import json
options_reader = open('.\options.txt','r',encoding='UTF-8')
options = Options()
line = options_reader.readline()
while line:
line = line.replace('\n','')
if line != "--headless":
options.add_argument(line)
line = options_reader.readline()
options_reader.close()
# 在msedgedriver_path.txt填写webdriver的保存目录(win7填写绝对路径)
driver_reader = open('.\msedgedriver_path.txt','r',encoding='UTF-8')
driverPath = driver_reader.readline()
driver = webdriver.Edge(driverPath,options=options)
driver_reader.close()
# 记得写完整的url 包括http和https
driver.get('https://cn.bing.com/')
# 程序打开网页后30秒内 “手动登陆账户”
time.sleep(30)
with open('cookies.txt', 'w') as f:
# 将cookies保存为json格式
f.write(json.dumps(driver.get_cookies()))
driver.close()
print('用户Cookies读取完成')