Luu 2020-06-08
WebDriver操作Cookie的方法如下:
from selenium import webdriver driver = webdriver.Chrome() driver.get("http://www.baidu.com") # 获取所有cookie信息并打印 cookie = driver.get_cookies() print(cookie)
执行结果为:
[{‘httpOnly‘: False, ‘name‘: ‘H_PS_PSSID‘, ‘path‘: ‘/‘, ‘domain‘: ‘baidu.com‘, ‘value‘: ‘1438_21121_29523_29518_29721_29567_29221_22159‘, ‘secure‘: False}, {‘httpOnly‘: False, ‘name‘: ‘BDORZ‘, ‘path‘: ‘/‘, ‘expiry‘: 1568361981.071032, ‘domain‘: ‘baidu.com‘, ‘value‘: ‘B490B5EBF6F3CD402E515D22BCDA1598‘, ‘secure‘: False}, {‘httpOnly‘: False, ‘name‘: ‘BD_UPN‘, ‘path‘: ‘/‘, ‘expiry‘: 1569139581, ‘domain‘: ‘www.baidu.com‘, ‘value‘: ‘12314753‘, ‘secure‘: False}, {‘httpOnly‘: False, ‘name‘: ‘BD_HOME‘, ‘path‘: ‘/‘, ‘domain‘: ‘www.baidu.com‘, ‘value‘: ‘0‘, ‘secure‘: False}, {‘httpOnly‘: False, ‘name‘: ‘PSTM‘, ‘path‘: ‘/‘, ‘expiry‘: 3715759227.723611, ‘domain‘: ‘baidu.com‘, ‘value‘: ‘1568275579‘, ‘secure‘: False}, {‘httpOnly‘: False, ‘name‘: ‘delPer‘, ‘path‘: ‘/‘, ‘domain‘: ‘baidu.com‘, ‘value‘: ‘0‘, ‘secure‘: False}, {‘httpOnly‘: False, ‘name‘: ‘BIDUPSID‘, ‘path‘: ‘/‘, ‘expiry‘: 3715759227.723592, ‘domain‘: ‘baidu.com‘, ‘value‘: ‘79138395196A3C2A6CA4959816433748‘, ‘secure‘: False}, {‘httpOnly‘: False, ‘name‘: ‘BD_LAST_QID‘, ‘path‘: ‘/‘, ‘expiry‘: 1568275581.723628, ‘domain‘: ‘www.baidu.com‘, ‘