作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
返回的cookies如下:
[
{
"domain": "www.carid.com",
"name": "uxatc",
"value": "%13%18%07%13%0D%07%13J%07%14J%07%0DJ%07%13%14%07%13I%07%12%13%0F%09%0E%1E%07%13%1F%1D%1A%17%08%1E%07%14%0F%1D%1A%17%08%1E%07%08%17%0F%09%0E%1E%07%16%16%07%16%1F%07%0F%08%07%0F%16%07%10%1F%07%15%16%07%0D%08%0D%12%08%12%19%17%1E%07%0C%10%07%1F%1F%07%1F%10%07%0C%1F%07%15%0C%1D%1A%17%08%1E%07%1F%19%07%03%02%07%08%18%07%0FJJNMMINOJLJCLK%07%0FI%07",
"path": "/",
"httpOnly": false,
"secure": false
},
{
"domain": ".carid.com",
"name": "xid",
"value": "21f70e8bba820dcaf620307b1717f90c",
"path": "/",
"httpOnly": true,
"secure": false
},
{
"domain": ".carid.com",
"name": "xidRes",
"value": "21f70e8bba820dcaf620307b1717f90c",
"expiry": 1567463776,
"path": "/",
"httpOnly": true,
"secure": false
},
{
"domain": "www.carid.com",
"name": "store_language",
"value": "US",
"expiry": 1597790176,
"path": "/",
"httpOnly": false,
"secure": true
},
{
"domain": "www.carid.com",
"name": "uxat",
"value": "%13%18K%07%0DJ%07%13J%1D%1A%17%08%1E%07%14J%1D%1A%17%08%1E%07%13%1F%1D%1A%17%08%1E%07%14%0F%1D%1A%17%08%1E%07%08%17%0F%09%0E%1E%07%16%16%07%16%1F%07%0F%08%07%0F%16%07%10%1F%07%15%16%07%0D%08%0D%12%08%12%19%17%1E%07%0C%10%07%1F%1F%07%1F%10%07%0C%1F%07%15%0C%1D%1A%17%08%1E%07%1F%19%07%13IK%07",
"path": "/",
"httpOnly": false,
"secure": false
},
{
"domain": "www.carid.com",
"name": "uxid2",
"value": "16fc88Ve3eb83cfbccGc5",
"path": "/",
"httpOnly": false,
"secure": false
},
{
"domain": "www.carid.com",
"name": "uxid",
"value": "8a58hVe3eb83cfc13Ym8",
"path": "/",
"httpOnly": false,
"secure": false
}
]
有 7 个 cookie,但浏览器有 17 个 cookie:
最佳答案
可能是因为在获取 cookie 之前您没有等待页面完全加载。我检查了网站并观察了 cookie 状态。在汽车选择 div 上完全加载页面之前,cookie 比页面完全加载后少。
即使驱动程序认为页面已完全加载,也可能不是。它可能会运行一些后台脚本。在你想做任何事情之前,最好先检查一下。
工作示例:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
opt = webdriver.FirefoxOptions()
# opt.headless = True
driver = webdriver.Firefox(options=opt)
driver.delete_all_cookies()
driver.get("https://carid.com")
cookies_before = driver.get_cookies()
WebDriverWait(driver, 15).until(
EC.visibility_of_element_located(
(By.XPATH, '//div[contains(@class, "select-vehicle-button")]')
))
print("Loaded!")
cookies_after = driver.get_cookies()
print(bool(cookies_before == cookies_after))
print(f"Cookies before: {len(cookies_before)}.")
print(f"Cookies after: {len(cookies_after)}.")
print(cookies_after)
driver.quit()
前后不同时的输出(仅有时):
Loaded!
False
Cookies before: 5.
Cookies after: 17.
关于python - Selenium:driver.get_cookies() 返回不完整的 cookie 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57568626/
返回的cookies如下: [ { "domain": "www.carid.com", "name": "uxatc", "value": "
下面是我的脚本: # -*- coding: UTF-8 -*- from selenium import webdriver driver = webdriver.Firefox() driver.
我是一名优秀的程序员,十分优秀!