获取cookies
from selenium import webdriver
import time
import json
chrome_path = "chromedriver.exe"
driver = webdriver.Chrome(executable_path=chrome_path)
driver.get("https://passport.jd.com/new/login.aspx")
time.sleep(10)
cookies = driver.get_cookies()
jsonCookies = json.dumps(cookies) # 转换成字符串保存
with open('cookies.txt', 'w') as f:
f.write(jsonCookies)
登入JD
# coding:utf-8
from selenium import webdriver
import json
# 调用驱动
chrome_path = "chromedriver.exe"
driver = webdriver.Chrome(executable_path=chrome_path)
# 先勾引一下才能登入
driver.get("http://www.jd.com")
with open('cookies.txt', 'r', encoding='utf8') as f:
listCookies = json.loads(f.read())
for cookie in listCookies:
driver.add_cookie(cookie)
# 用户登入jd
driver.get("http://www.jd.com")