python爬虫之selenium+打码平台识别验证码
1、常用的打码平台:超级鹰、打码兔等
2、打码平台在识别图形验证码和点触验证码上比较好用
(1)12306点触验证码
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from chaojiying import Chaojiying_Client
from account import USERNAME12306, PASSWORD12306, USERNAMECJY, PASSWORDCJY
import time class TrainLogin(object):
def __init__(self, username, password):
self.username = username
self.password = password
self.index_url = "https://www.12306.cn/index/"
self.login_url = "https://kyfw.12306.cn/otn/resources/login.html"
self.code_path = r"E:\vscode\Python\超级鹰验证码识别\chaojiying_Python\12306.png"
self.chrome = webdriver.Chrome(r"D:\chromedriver_win32\chromedriver.exe")
self.chaojiying = Chaojiying_Client(USERNAMECJY, PASSWORDCJY, "") def login(self):
self.pre_set()
self.come_login_url()
self.process_username_password()
while True:
self.process_captchar()
if self.success_login():
print("成功登陆!!!")
break
time.sleep(5)
self.chrome.quit() def pre_set(self):
self.chrome.implicitly_wait(1)
self.chrome.maximize_window() def come_login_url(self):
self.chrome.get(self.login_url)
WebDriverWait(self.chrome, 5).until(EC.presence_of_element_located((By.LINK_TEXT, "账号登录")))
self.chrome.find_element_by_link_text("账号登录").click() def process_username_password(self):
self.chrome.find_element_by_id("J-userName").send_keys(self.username)
time.sleep(1)
self.chrome.find_element_by_id("J-password").send_keys(self.password) def process_captchar(self):
self.chrome.find_element_by_class_name("login-pwd-code").screenshot(self.code_path)
with open(self.code_path, "rb") as fp:
img = fp.read()
res = self.chaojiying.PostPic(img, 9004)["pic_str"]
pos_ls = self.get_postion_ls(res)
action_chains = ActionChains(self.chrome)
for pos in pos_ls:
action_chains.move_to_element_with_offset(self.chrome.find_element_by_class_name("login-pwd-code"),
pos[0], pos[1]).click().release().perform()
time.sleep(0.5)
action_chains = ActionChains(self.chrome) def success_login(self):
self.chrome.find_element_by_id("J-login").click()
try:
WebDriverWait(self.chrome, 5).until(EC.text_to_be_present_in_element((By.CLASS_NAME, "welcome-name"), "XXX"))
except:
return False
else:
return True def get_postion_ls(self, pos_str):
pos_ls = []
for pa in pos_str.split("|"):
pos = []
for pb in pa.split(","):
pos.append(int(pb))
pos = tuple(pos) pos_ls.append(pos)
return pos_ls if __name__ == "__main__":
loginer = TrainLogin(USERNAME12306, PASSWORD12306)
loginer.login()
(2)哔哩哔哩点触验证码
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from chaojiying import Chaojiying_Client
from account import USERNAMEBL, PASSWORDBL, USERNAMECJY, PASSWORDCJY
import time class BiLiLogin(object):
def __init__(self, username, password):
self.username = username
self.password = password
self.chrome = webdriver.Chrome(r"D:\chromedriver_win32\chromedriver.exe")
self.code_path = r"E:\vscode\Python\超级鹰验证码识别\chaojiying_Python\bili.png"
self.login_url = "https://passport.bilibili.com/login"
self.chaojiying = Chaojiying_Client(USERNAMECJY, PASSWORDCJY, "") def login(self):
self.pre_set()
self.come_login_win()
self.process_username_password()
while True:
self.process_captchar()
if self.is_success():
print("登录成功!!!")
break
print(self.chrome.get_cookies())
# 延迟十秒退出
time.sleep(10)
self.chrome.quit() def pre_set(self):
self.chrome.implicitly_wait(1)
self.chrome.maximize_window() def come_login_win(self):
self.chrome.get(self.login_url) def process_username_password(self):
self.chrome.find_element_by_id("login-username").send_keys(self.username)
self.chrome.find_element_by_id("login-passwd").send_keys(self.password)
self.chrome.find_element_by_class_name("btn-login").click() def process_captchar(self):
WebDriverWait(self.chrome, 5).until(EC.presence_of_element_located((By.CLASS_NAME, "geetest_widget")))
time.sleep(5)
self.chrome.find_element_by_class_name("geetest_widget").screenshot(self.code_path)
with open(self.code_path, "rb") as fp:
img = fp.read()
pos_str = self.chaojiying.PostPic(img, "")["pic_str"]
pos_ls = self.get_postion_ls(pos_str)
for pos in pos_ls:
action_chain = ActionChains(self.chrome)
action_chain.move_to_element_with_offset(self.chrome.find_element_by_class_name("geetest_widget"), pos[0], pos[1]).click().release().perform()
time.sleep(0.5)
self.chrome.find_element_by_class_name("geetest_commit").click() def is_success(self):
try:
WebDriverWait(self.chrome, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "nickname")))
except:
return False
else:
return True def get_postion_ls(self, pos_str):
pos_ls = []
for pa in pos_str.split("|"):
pos = []
for pb in pa.split(","):
pos.append(int(pb))
pos = tuple(pos) pos_ls.append(pos)
return pos_ls if __name__ == "__main__":
loginer = BiLiLogin(USERNAMEBL, PASSWORDBL)
loginer.login()
python爬虫之selenium+打码平台识别验证码的更多相关文章
- Python爬虫教程-29-验证码识别-Tesseract-OCR
本篇是关于验证码识别问题,也是Python爬虫笔记的一个结尾,使用 Tesseract Python爬虫教程-29-验证码识别-Tesseract-OCR 常见反爬虫手段: 验证码 1.简单图片,扭曲 ...
- [Python爬虫]使用Selenium操作浏览器订购火车票
这个专题主要说的是Python在爬虫方面的应用,包括爬取和处理部分 [Python爬虫]使用Python爬取动态网页-腾讯动漫(Selenium) [Python爬虫]使用Python爬取静态网页-斗 ...
- Python 爬虫利器 Selenium 介绍
Python 爬虫利器 Selenium 介绍 转 https://mp.weixin.qq.com/s/YJGjZkUejEos_yJ1ukp5kw 前面几节,我们学习了用 requests 构造页 ...
- Python爬虫之selenium的使用(八)
Python爬虫之selenium的使用 一.简介 二.安装 三.使用 一.简介 Selenium 是自动化测试工具.它支持各种浏览器,包括 Chrome,Safari,Firefox 等主流界面式浏 ...
- Python爬虫之selenium高级功能
Python爬虫之selenium高级功能 原文地址 表单操作 元素拖拽 页面切换 弹窗处理 表单操作 表单里面会有文本框.密码框.下拉框.登陆框等. 这些涉及与页面的交互,比如输入.删除.点击等. ...
- Python爬虫之selenium库使用详解
Python爬虫之selenium库使用详解 本章内容如下: 什么是Selenium selenium基本使用 声明浏览器对象 访问页面 查找元素 多个元素查找 元素交互操作 交互动作 执行JavaS ...
- selenium自动化 | 借助百度AI开放平台识别验证码登录职教云
#通过借助百度AI开放平台识别验证码登录职教云 from PIL import Image from aip import AipOcr import unittest # driver.get(zj ...
- Python 通过打码平台实现验证码
在爬虫时,经常遇到登录需要验证码的情况,简单的验证码可以自己解决,复制的验证码需要借助机器学习,有一定的难度.还有一个简单的方案就是采用付费的打码平台. 比如R若快(http://www.ruokua ...
- Python爬虫学习笔记之微信宫格验证码的识别(存在问题)
本节我们将介绍新浪微博宫格验证码的识别.微博宫格验证码是一种新型交互式验证码,每个宫格之间会有一条 指示连线,指示了应该的滑动轨迹.我们要按照滑动轨迹依次从起始宫格滑动到终止宫格,才可以完成验证,如 ...
随机推荐
- 第二代网关GateWay搭建流程
Spring Cloud第二代网关GateWay是由纯Netty开发,底层为Reactor,WebFlux构建,不依赖任何Servlet容器,它不同于Zuul,使用的是异步IO,性能较Zuul提升1. ...
- 【转】Fst指数
[转]Fst指数 转载自 http://blog.csdn.net/zhu_si_tao/article/details/71513099 与 http://blog.sina.com.cn/s/bl ...
- 【lca+输入】Attack on Alpha-Zet
Attack on Alpha-Zet 题目描述 Space pirate Captain Krys has recently acquired a map of the artificial and ...
- DataSet,DataTable排序(转载)
DataSet,DataTable排序 关于对已经绑定的DataSet的排序的问题: DataSet ds=new DataSet();DataView dv=new DataView();dv. ...
- idea发布web项目在tomcat位置问题
(1)war模式这种可以称之为是发布模式,看名字也知道,这是先打成war包,再发布. (2)war exploded模式是直接把文件夹.jsp页面 .classes等等移到Tomcat 部署文件夹里面 ...
- MySQL_语句
一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname 3.说明:备份sql server--- 创建 ...
- Python - 使用 PostgreSQL 数据库
基本用法 # -*- coding: utf-8 -*- # !/usr/bin/python # 需要安装下面的驱动包 import psycopg2 # 连接到一个现有的数据库,如果数据库不存在, ...
- Linux安装svn服务
安装svn yum -y install subversion 创建保存仓库/版本库的目录 mkdir -p /opt/data/svndir 创建仓库/版本库, 这里同时创建两个仓库(project ...
- JQuery实现复制数据到剪贴板之各种麻花与右键点击弹出选择菜单
1.如果小伙伴们只是想实现点击某个按钮(通过click事件)实现复制功能. 那小哥哥我在这里推荐大家使用2个非常好用的插件 (1)clipboard.js:纯js插件,无需flash,相对来说更轻量级 ...
- 高级I/O
1.阻塞问题的几种解决模型 1.1 非阻塞模型:类似于死循环,需要适当加休眠,防止cpu占用太高:效率较低 1.2 线程异步:效率最高的一种解决方案 1.3 I/O多路转接与复用 select(低) ...