Python+selenium通过设置Cookie绕过验证码登录。
2019-02-20 16:31
1036 查看
selenium+ python3 添加cookie绕过验证码登陆
1.背景介绍
最近做一个Web自动化项目,但是每次登陆都需要验证码验证,真的是头痛啊,破解验证码需要对验证码图片进行训练模型并且识别率低,查找文档,发现webdriver还提供add_cookie这个方法,完美解决了登录验证的问题。
2. 添加cookie方法:driver.add_cookie()
1.add_cookie(cookie_dict)方法里面参数是cookie_dict,说明里面参数是字典类型。
2.add_cookie的源码。
3. add_cookie字典格式。
[code]cookie = { "domain": ".baidu.com", # 域名 "name"': name, # cookie的name "value": value, # cookie的value "expires": "", # cookie的过期时间 'path': '/', # 路径 'httpOnly': False, # 自行百度,这里不多描述 'HostOnly': False, # 自行百度,这里不多描述 'Secure': False # 自行百度,这里不多描述}
我们可以通过查看谷歌浏览器的cookie构造来校验我们的字典格式
3.实践是否能跳过登录----拿百度举例,以下是代码。
[code]""" @author: luyefei @file:skip_captcha.py @time:2019/2/20 """ from selenium import webdriver import time class SkipCaptcha(object): def __init__(self): self.driver = webdriver.Chrome() self.cookie = {"domain": ".baidu.com", 'name': "BAIDUID", 'value': "777DDDB3D7FCC909D29A0D06C9F44166CA8:FG=1", "expires": "2039-02-15T08:24:00.000Z", 'path': '/', 'httpOnly': False, 'HostOnly': False, 'Secure': True} def login(self): driver = self.driver driver.get("http://www.baidu.com/") time.sleep(2) driver.add_cookie(self.cookie) time.sleep(2) driver.get("https://i.baidu.com/") if __name__ == '__main__': r = SkipCaptcha() r.login()
相关文章推荐
- Python Selenium Cookie 绕过验证码实现登录
- Python Selenium Cookie 绕过验证码实现登录示例代码
- python接口自动化4-绕过验证码登录(cookie)
- selenium2java通过第三方登录绕过知乎登陆验证码
- Selenium WebDriver对cookie进行处理绕过登录验证码
- Selenium2+python自动化41-绕过验证码(add_cookie)
- python接口自动化4-绕过验证码登录(cookie)
- selenium(java)通过Cookie跳过登录验证码
- selenium+python,driver.add_cookie()跳过登录验证码
- Python+selenium 将登录操作设置为公共模块
- 自动化测试 -- 通过Cookie跳过登录验证码
- Python+Selenium+PIL+Tesseract自动识别验证码进行一键登录
- 自动化测试 -- 通过Cookie跳过登录验证码
- python 利用selenium模拟登录帐号验证网站并获取cookie
- 自动化测试 -- 通过Cookie跳过登录验证码
- python通过cookie模拟已登录状态的初步研究
- 自动化测试 -- 通过Cookie跳过登录验证码
- Python使用selenium实现网页用户名 密码 验证码自动登录功能
- python通过cookie模拟已登录状态的初步研究