添加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. CF916C

    题目链接:http://codeforces.com/contest/916/problem/C 题目大意: 用\(n\)个结点,\(m\)条边(每条边的权值范围为[1, 109]) 构造出一个无向带 ...

  2. CF894C Marco and GCD Sequence

    题目链接:http://codeforces.com/contest/894/problem/C 题目大意: 按照严格递增的顺序给出 \(m\) 个数作为公因数集,请你构造出一个数列,对于数列中的任意 ...

  3. 设计模式系列之单例模式(Singleton Pattern)——确保对象的唯一性

    模式概述 模式定义 模式结构图 饿汉式单例与懒汉式单例 饿汉式单例 懒汉式单例 模式应用 模式在JDK中的应用 模式在开源项目中的应用 模式总结 主要优点 适用场景 说明:设计模式系列文章是读刘伟所著 ...

  4. 【Mac 实用技巧】不定期更新

    Mac去掉截屏图片边框外阴影效果 一次命令行:defaults write com.apple.screencapture disable-shadow -bool true;\killall Sys ...

  5. xshell行号显示

    xshell显示行号: 输入命令: vim ~/.vimrc 输入: set nu 之后在打开文件 就可以 看到行号显示.

  6. PIC单片机的i2c的程序

    #include<pic.h>#define uchar unsigned char#define uint unsigned int#define add 0xaa__CONFIG(0x ...

  7. Android_存储之DataBase之Room

    概述: Room是Google在AndroidX中提供的一个ORM(Object Relational Mapping,对象关系映射)库.它是在SQLite上提供的一个抽象层,可以使用SQLite的全 ...

  8. vue-cli4 + TS构建新项目

    1. 如果你之前没有安装vue-cli,可以通过如下命令进行安装: npm install -g @vue/cli yarn global add @vue/cli 2. 创建vue项目 vue cr ...

  9. 当微信小程序遇到云开发,再加上一个类似 ColorUI 的模板,人人都能做小程序了

    作为一个 Java 程序员,早就想尝试一把微信小程序,但是一直苦于没有想法,再加上做一个漂亮的页面实在不太擅长. 由于自己比较喜欢历史,经常看历史方面的书.在一次梳理中国现有的朝代时,突然想到,要是可 ...

  10. Rocket - debug - TLDebugModuleInner - HARTINFO

    https://mp.weixin.qq.com/s/9GjZAax0SZhRqLne16jn-w 简单介绍TLDebugModuleInner中HARTINFO寄存器的实现. 1. HARTINFO ...