google浏览器版本
Google Chrome : 79.0.3945.88 (正式版本) (64 位) (cohort: Stable)
查看chrome信息:
chrome://version/
python selenium chrome 加载本地用户配置,并cookie保存到本地文件
代码语言:javascript复制#!/usr/bin/env python
# encoding: utf-8
from selenium import webdriver
import time
import json
class Spider:
def main(self, url):
option = webdriver.ChromeOptions()
option.add_argument(r'--user-data-dir=C:UsersUserAppDataLocalGoogleChromeUser Data')
option.add_argument('--profile-directory=Default')
browser = webdriver.Chrome(options=option)
browser.get(url)
browser.implicitly_wait(60)
time.sleep(20)
try:
# 获取登陆成功后的cookie信息
login_rear_cookie = browser.get_cookies()
if login_rear_cookie:
# 把cookie信息用json序列化后写入cookie.txt文件
with open('cookie.txt', 'w') as f:
f.write(json.dumps(login_rear_cookie))
print('获取cookie信息成功')
except Exception as e:
print('获取cookie失败:{}'.format(e))
finally:
browser.quit()
if __name__ == '__main__':
url = "https://www.jd.com/"
st = Spider()
st.main(url)