from seleniumimport webdriver
from selenium.webdriverimport ActionChains
driver = webdriver.Chrome()
#獲取到cookies
def get_cookies():
driver.get('https://www.163.com/')
Lg_bt = driver.find_element_by_id('js_N_nav_login_title')
ActionChains(driver).move_to_element(Lg_bt).perform()
input('輸入完密碼請(qǐng)輸入q')
cookies = driver.get_cookies()
return cookies
cookies = get_cookies()
driver = webdriver.Chrome()
driver.get('https://www.163.com/')
driver.delete_all_cookies()
for cookiein cookies: #遍歷cookies桨吊,刪掉expiry過(guò)期時(shí)間巫俺,然后加載到cookie()傳給driver
if 'expiry' in cookie.keys():
del cookie['expiry']
driver.add_cookie(cookie)
driver.refresh()