绕过验证码,使用chrome的已存在的cookie访问网站

来源:互联网 发布:伊修巴尔歼灭战 知乎 编辑:程序博客网 时间:2024/06/10 18:48
'''chrome浏览器的处理:登录页面有验证码的,通过cookie处理:先手工登录,记住密码;写自动化测试脚本时,通过读取该浏览器本地的cookie文件打开该页面就是登录状态了。好处是跳过登录页面的验证码识别;'''from selenium import webdriverfrom time import sleepimport os#chrome存放cookie的路径profile_dir = r'C:\Users\Administrator\AppData\Local\Google\Chrome\User Data'chrome_options = webdriver.ChromeOptions()chrome_options.add_argument("user-data-dir=" + os.path.abspath(profile_dir))#重写浏览器驱动时,如果没有参数的话,则打开的就是一个全新的没有任何cookie的浏览器driver = webdriver.Chrome(chrome_options=chrome_options)driver.get(r'http://www.baidu.com')#已经就是登录状态了!sleep(5)driver.quit()
http://m.blog.csdn.net/article/details?id=45888641
                                             
0 0
原创粉丝点击