添加cookie绕过登陆

#!/usr/bin/env python
# -*- coding: utf-8 -*- from selenium import webdriver
import time
import pickle class SkipLogin(object):
def __init__(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(15)
self.driver.maximize_window() def add_have_login_state(self):
try:
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
cookie_dict = {
"domain": ".yaozh.com", # 火狐浏览器不用填写domain,谷歌要需要
'name': cookie.get('name'),
'value': cookie.get('value'),
"expires": "",
'path': '/',
'httpOnly': False,
'HostOnly': False,
'Secure': False}
self.driver.add_cookie(cookie_dict)
except Exception as e:
print(e) # 打开个人中心
def open_personal_center(self):
self.driver.get("https://www.yaozh.com/member/") def is_login(self):
return self.driver.current_url is not "https://www.yaozh.com/member/" # 添加cookies到文件中
def write_cookies(self):
self.driver.get("https://www.yaozh.com/login/")
user_name = self.driver.find_element_by_id("username")
pwd = self.driver.find_element_by_id("pwd")
login_button = self.driver.find_element_by_id("button")
user_name.send_keys("")
pwd.send_keys("ybeuofnw")
login_button.click()
time.sleep(5)
pickle.dump(self.driver.get_cookies(), open("cookies.pkl", "wb"))
time.sleep(5)
self.driver.close() def main(self):
self.open_personal_center()
if self.is_login():
self.add_have_login_state()
# 这里要加一个判断cookie是否有效判断,可以通过页面判断
time.sleep(5)
self.open_personal_center()
time.sleep(5)
self.driver.close() if __name__ == '__main__':
sl = SkipLogin()
# sl.write_cookies()
sl.main()

添加cookie绕过登陆的更多相关文章

  1. selenium3.7+ python3 添加cookie模拟登陆

    一.背景介绍 最近做一个爬虫项目,用selenium调用浏览器去获取渲染后的源码,但是每次登陆都需要手机验证,这真的是头痛啊,这种验证方式不要想着去破解,还是老老实实用手机收验证码去吧!反正我是不知道 ...

  2. katalon系列十五:给浏览器添加cookie自动登陆

    import org.openqa.selenium.Cookieimport org.openqa.selenium.WebDriverimport com.kms.katalon.core.web ...

  3. php curl 添加cookie伪造登陆抓取数据(摘自网络)

    有的网页必须登陆才能看到,这个时候想要抓取信息必须在header里面传递cookie值才能获取 1.首先登陆网站,打开firebug就能看到对应的cookie把这些cookie拷贝出来就能使用了 2. ...

  4. selenium webdriver 如何添加cookie

    一. webdriver中常用的cookie方法 webdriver中提供了操作cookie的相关方法: get_cookies()                  获得cookie信息 add_c ...

  5. selenium webdriver如何添加cookie

    一. webdriver中常用的cookie方法 webdriver中提供了操作cookie的相关方法: get_cookies()                  获得cookie信息 add_c ...

  6. python接口自动化(十三)--cookie绕过验证码登录(详解)

    简介 有些登录的接口会有验证码:短信验证码,图形验证码等,这种登录的话验证码参数可以从后台获取的(或者查数据库最直接).获取不到也没关系,可以通过添加cookie的方式绕过验证码.(注意:并不是所有的 ...

  7. Python Selenium Cookie 绕过验证码实现登录

    Python Selenium Cookie 绕过验证码实现登录 之前介绍过博客园的通过cookie 绕过验证码实现登录的方法.这里并不多余,会增加分析和另外一种方法实现登录. 1.思路介绍 1.1. ...

  8. Python - Cookie绕过验证码登录

    前言 有些登录的接口会有验证码:短信验证码,图形验证码等,这种登录的话验证码参数可以从后台获取的(或者查数据库最直接). 获取不到也没关系,可以通过添加cookie的方式绕过验证码. 另一篇博文  P ...

  9. 通过cookie绕过验证码登录

    在我们做自动化的时候碰到一些比较难破解的验证码时是非常头疼的,一般来说最好的办法就是让开发屏蔽,这样最有益身心健康. 那么今天我介绍的这个方法也挺简单的,就是通过添加cookie的方式绕过验证码直接登 ...

随机推荐

  1. PAT-1063 Set Similarity (set集合)

    1063. Set Similarity Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*1 ...

  2. poj2778 AC自动机

    以下内容均为转载,,只有代码是自己写的=-= http://blog.csdn.net/morgan_xww/article/details/7834801   转载地址 博主写的很好 ------- ...

  3. GYM101635E Ingredients

    题目链接:https://vjudge.net/problem/Gym-101635E 题目大意: 给定一个有 \(N\) 条边的有向无环图(有多个起点),每条边都有其费用和收益,现要从一个或多个起点 ...

  4. xv6 操作系统的环境搭建

    xv6 是 MIT 设计的一个教学型操纵系统.xv6 可在 Intel X86 框架上运行,为了方便,建议将 xv6 运行在 QEMU 虚拟机器上,本人的实验环境是 ubuntu 18.04 . 1. ...

  5. SpringBoot2.1电商通用(微信+支付宝)支付系统实战

    『课程目录』: ├─第10章 全模块电商系统之商品模块 │      10-1_商品列表-上.mp4 │      10-2_商品列表-中.mp4 │      10-3_商品列表-下.mp4 │  ...

  6. OpenResty高性能web平台

    openresty高性能web平台安装使用 简介:OpenResty® 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用 ...

  7. MyBatis——com.mysql.cj.exceptions.InvalidConnectionAttributeException

    报错信息 Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.c ...

  8. 封装 private

    封装表现: 1.方法就是一个最基本封装体. 2.类其实也是一个封装体. 从以上两点得出结论,封装的好处: 1.提高了代码的复用性. 2.隐藏了实现细节,还要对外提供可以访问的方式.便于调用者的使用.这 ...

  9. SpringCloud(三)- OpenFeign简介及@FeignClient等注解的使用

    唯能极于情,故能极于剑 有问题或错误请及时联系小编或关注小编公众号 "CodeCow",小编一定及时回复和改正,期待和大家一起学习交流 此文由四部分组成(OpenFeign简介.@ ...

  10. sql注入讲解

    1.输入1' 发现数据库报错,原因是我们的输入直接被代入到数据库查询语句里面. 2.有没有办法可以不让他报错呢?可以尝试一下构造正确的数据库语法,使之不报错.比如输入 1 and 1=1 试试 sel ...