add_cookie跳过验证码登录

上一篇 / 下一篇  2019-04-04 22:24:13

fromseleniumimportwebdriver

url ='*******'
driver = webdriver.Chrome()
driver.get(url)
driver.find_element_by_xpath('//*[@id="username"]').send_keys('****')
driver.find_element_by_xpath('//*[@id="ff"]/div/div[3]/input').send_keys('********')
driver.find_element_by_xpath('//*[@id="sub"]').click()
cookie = driver.get_cookies()
print(cookie)
[{'domain': '***', 'httpOnly': True, 'name': '***', 'path': '/***', 'secure': False, 'value': '***'}]
获取cookie后是list格式的,但是add_cookie需要的是dict格式的所以我们需要转化一下
cookie[0]就是list的第一个dict
driver.add_cookie(cookie[0]) 就可以添加cookie了。

driver = webdriver.Chrome()
driver.get(url)
driver.add_cookie(cookie[0])
driver.get(url)
这样子登录就可以跳过输入账号,密码,验证码的过程了

TAG:

 

评分:0

我来说两句

王承庆

王承庆

今天也是充满希望的一天!

我的栏目

日历

« 2024-03-28  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 2177
  • 日志数: 11
  • 建立时间: 2019-03-22
  • 更新时间: 2019-06-10

RSS订阅

Open Toolbar