selenium 操作 chrome driver 对 https 协议的网站进行 cookies 操作
环境情况
- java 语言
- selenium 2.53.0 版本
- chrome 版本 72.0.3626
使用 selenium 控制 chrome driver 登录百度
通过 selenium 操作chrome浏览器登录百度,然后记录下登录之后的 cookies 信息,cookie中的secure的值都是false(这是正确的)
{"domain":".baidu.com","expiry":1812100382000,"httpOnly":true,"name":"BDUSS","path":"/","secure":false,"value":"XlrWjR3TGhIYWtaVHo41w2YY9cd"}
{"domain":".www.baidu.com","expiry":2498980384000,"httpOnly":false,"name":"sugstore","path":"/","secure":false,"value":"1"}
{"domain":".baidu.com","httpOnly":false,"name":"delPer","path":"/","secure":false,"value":"0"}
{"domain":".baidu.com","expiry":3700384001000,"httpOnly":false,"name":"BIDUPSID","path":"/","secure":false,"value":"3BA3A71DA2697"}
{"domain":".baidu.com","expiry":3700384001000,"httpOnly":false,"name":"PSTM","path":"/","secure":false,"value":"1552900379"}
{"domain":".baidu.com","httpOnly":false,"name":"H_PS_PSSID","path":"/","secure":false,"value":"1420_21086_18560_20883_28557_28608_28585_28603"}
{"domain":"www.baidu.com","expiry":1553764384000,"httpOnly":false,"name":"BD_UPN","path":"/","secure":false,"value":"12314353"}
{"domain":".baidu.com","expiry":3700384001000,"httpOnly":false,"name":"BAIDUID","path":"/","secure":false,"value":"3BA3A71DA2697:FG=1"}
{"domain":"www.baidu.com","httpOnly":false,"name":"BD_HOME","path":"/","secure":false,"value":"1"}
但是当我再次自己新打开浏览器进入百度首页,把cookies信息写进去之后,再读取cookies信息,其中的值变成了 true。导致错误 - 因为如果cookie的 secure 设置为 true之后,如果是在https网站下设置的,那么将无法进入当前域名的其他 http 的页面(丢失登录信息)。
{"domain":"baidu.com","expiry":1812100382000,"httpOnly":false,"name":"BDUSS","path":"/","secure":false,"value":"XlrWjR3TG1w2YY9cd"}
{"domain":"www.baidu.com","expiry":2498980384000,"httpOnly":false,"name":"sugstore","path":"/","secure":false,"value":"1"}
{"httpOnly":false,"name":"delPer","path":"/","secure":false,"value":"0"}
{"domain":"baidu.com","expiry":3700384001000,"httpOnly":false,"name":"BIDUPSID","path":"/","secure":false,"value":"3BA3A7CAA4"}
{"httpOnly":false,"name":"BDRCVFR[f83LjLo_kJ6]","path":"/","secure":false,"value":"mk3SLVN4HKm"}
{"domain":"baidu.com","expiry":3700384001000,"httpOnly":false,"name":"PSTM","path":"/","secure":false,"value":"1552900379"}
{"domain":"www.baidu.com","expiry":1553764384000,"httpOnly":false,"name":"BD_UPN","path":"/","secure":false,"value":"12314353"}
{"httpOnly":false,"name":"H_PS_PSSID","path":"/","secure":false,"value":"1420_21086_18560_20883_28557_28608_28585_28603"}
{"domain":"baidu.com","expiry":3700384001000,"httpOnly":false,"name":"BAIDUID","path":"/","secure":false,"value":"3BA3ACAA4:FG=1"}
{"httpOnly":false,"name":"BD_HOME","path":"/","secure":false,"value":"1"}
注意:我在Edge 和 IE 中都有测试,这两个浏览器都没有问题,唯独chrome浏览器在https的时候,写入cookies会变成 true
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论