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爬虫学习笔记之微信宫格验证码的识别(存在问题)
本节我们将介绍新浪微博宫格验证码的识别.微博宫格验证码是一种新型交互式验证码,每个宫格之间会有一条 指示连线,指示了应该的滑动轨迹.我们要按照滑动轨迹依次从起始宫格滑动到终止宫格,才可以完成验证,如 ...
随机推荐
- 常见 Web 安全攻防总结
Web 安全的对于 Web 从业人员来说是一个非常重要的课题,所以在这里总结一下 Web 相关的安全攻防知识,希望以后不要再踩雷,也希望对看到这篇文章的同学有所帮助.今天这边文章主要的内容就是分析几种 ...
- 达梦、oracel、mysql数据库兼容
联合表更新sql语句: 只支持mysql.oracle,不支持达梦 update to_pub_report a, to_pub_rec_process b set a.Satisfy_ID , a. ...
- LeetCode No.133,134,135
No.133 CloneGraph 克隆图 题目 给你无向 连通 图中一个节点的引用,请你返回该图的 深拷贝(克隆). 图中的每个节点都包含它的值 val(int) 和其邻居的列表(list[Node ...
- IP命令介绍
ip指令可以显示或操作路由.网络设备.设置路由策略和通道 1.语法 ip [选项] Object COMMAND [help] Object对象可以是: link 网络设备.addr 设备的协议 ...
- Box and Ball
题目描述 We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the o ...
- 网页元素检测工具:Spy_for_InternetExplorer下载地址
本工具用于实时查看IE浏览器中打开的网页中元素的信息.支持iframe.frame框架. 下载地址: Spy_for_InternetExplorer.rar
- WEB-文件包含漏洞详解
title date tags layout 文件包含漏洞(File Include) 2018-10-12 post 产生原因: 由于在编写代码时避免麻烦就需要把公用的一段代码写到一个单独的文件里面 ...
- K3CLOUD呼吸时间设置
- Longest Increasing Subsequence (Medium)
第一次做题思路201511092250 1.采用map存储,key为nums[i],value为以nums[i]为结尾的最大递增子序列的长度 2.采用map里面的lower_bounder函数直接找出 ...
- bug宝典linux篇 LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory(转)
升级glibc库后,使用xShell登录linux,提示: Connecting to ... Connection established. To escape to local shell, pr ...