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爬虫学习笔记之微信宫格验证码的识别(存在问题)
本节我们将介绍新浪微博宫格验证码的识别.微博宫格验证码是一种新型交互式验证码,每个宫格之间会有一条 指示连线,指示了应该的滑动轨迹.我们要按照滑动轨迹依次从起始宫格滑动到终止宫格,才可以完成验证,如 ...
随机推荐
- LeetCode No.148,149,150
No.148 SortList 排序链表 题目 在 O(n log n) 时间复杂度和常数级空间复杂度下,对链表进行排序. 示例 输入: 4->2->1->3 输出: 1->2 ...
- ubuntu下切换默认的python版本
Ubuntu系统自带python2.7(默认)和python3.5,所以不需要自己安装python.我们可以使用命令python -V或python3 -V来查看默认的python版本. 现在越来越多 ...
- Metasploit笔记
生成exe后门 msfvenom -p windows/meterpreter/reverse_tcp LHOST=IP LPORT=PORT -f exe -o 1987.exe 生成PHP后门 m ...
- 2017Google开发者大会
2017年12月14日有幸去上海跨国采购中心参加了2017Google开发者大会,这个大会有很多很有意思的展会以及技术分享.主题涵盖 Android.移动网络.Firebase.机器学习.云服务.AR ...
- bootstrap 学习 ---css样式学习
bootstrap 适用于响应式布局,移动设备优先的web项目 1.学习bootstrap需要引入bootstrap的css,jquery,bootstrap的js,注意:jquery文件必须在boo ...
- 在SpringBoot中使用Junit测试
一:加入依赖 <dependency> <groupId>junit</groupId> <artifactId>junit</artifactI ...
- 用C语言实现的轴对称变换
#include<stdio.h> main() { int i,p,n,k,f,c,h,g,w; ][]; ;i<=;i++) { ;p<=;p++) { a[i][p]=i ...
- [LC] 124. Binary Tree Maximum Path Sum
Given a non-empty binary tree, find the maximum path sum. For this problem, a path is defined as any ...
- python3下scrapy爬虫(第十卷:scrapy数据存储进mysql)
上一卷中我将爬取的数据文件直接写入文本文件中,现在我将数据存储到mysql中,我依然用的是pymysql,这个很麻烦建表需要在外面建 这次代码只需要改变pipyline就行 来 现在看下结果: 对比发 ...
- cs231n spring 2017 lecture13 Generative Models
1. 非监督学习 监督学习有数据有标签,目的是学习数据和标签之间的映射关系.而无监督学习只有数据,没有标签,目的是学习数据额隐藏结构. 2. 生成模型(Generative Models) 已知训练数 ...