我正试图从网站获得cookie来自动执行某些请求。目前,我正在使用selenium的get_cookie函数来获取cookie。
driver.get_cookie("cookie-name-here")
返回一个字典格式如下:
{'domain': 'website-name-here', 'expiry': 29630, 'name': 'cookie-name', 'path': '/', 'value':'the-string-that-I-need'}
我只需要'value'属性下的数据如果有更简单的方法在JS中获得价值,我也愿意。
如果我有一个这样的字典:
cookies = {'domain': 'website-name-here', 'expiry': 29630, 'name': 'cookie-name', 'path': '/', 'value':'the-string-that-I-need'}
获取该值的最简单方法是使用.get
val = cookies.get('value')
print(val)
或者换句话说,下面的代码也应该返回值.
print(driver.get_cookie("cookie-name-here").get('value'))