Python+Selenium / 报错InvalidArgumentException:Message:invalid argument:invalid “expiry”

添加cookies到浏览器

driver.delete_all_cookies()
with open('cookiesJsonFile.json', 'r') as JsonFile:
	cookiesInfo = json.loads(JsonFile.read())
print(type(cookiesInfo), cookiesInfo)
for i in range(0,len(cookiesInfo)):
	driver.add_cookie(cookiesInfo[i])
driver.refresh()

Python+Selenium / 报错InvalidArgumentException:Message:invalid argument:invalid “expiry”_第1张图片

问题解决

方式一:
driver.delete_all_cookies()
with open('cookiesJsonFile.json', 'r') as JsonFile:
    cookiesInfo = json.loads(JsonFile.read())
print(type(cookiesInfo), cookiesInfo)
for cookie in cookiesInfo:
     print(type(cookie), cookie)
     if 'expiry' in cookie:
         del cookie['expiry']
     driver.add_cookie(cookie)
driver.refresh()

Python+Selenium / 报错InvalidArgumentException:Message:invalid argument:invalid “expiry”_第2张图片

方式二:
for cookie in cookiesInfo:
    if 'expiry' in cookie and 'expiry' is not None:
        cookie['expiry'] = int(cookie['expiry'])
    driver.add_cookie(cookie)

链接

本文用于个人记录
参考链接: https://www.cnblogs.com/an5456/p/11715938.html,侵删
如有不正确的地方,欢迎指正。

你可能感兴趣的:(Python+Selenium)