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+打码平台识别验证码的更多相关文章

  1. Python爬虫教程-29-验证码识别-Tesseract-OCR

    本篇是关于验证码识别问题,也是Python爬虫笔记的一个结尾,使用 Tesseract Python爬虫教程-29-验证码识别-Tesseract-OCR 常见反爬虫手段: 验证码 1.简单图片,扭曲 ...

  2. [Python爬虫]使用Selenium操作浏览器订购火车票

    这个专题主要说的是Python在爬虫方面的应用,包括爬取和处理部分 [Python爬虫]使用Python爬取动态网页-腾讯动漫(Selenium) [Python爬虫]使用Python爬取静态网页-斗 ...

  3. Python 爬虫利器 Selenium 介绍

    Python 爬虫利器 Selenium 介绍 转 https://mp.weixin.qq.com/s/YJGjZkUejEos_yJ1ukp5kw 前面几节,我们学习了用 requests 构造页 ...

  4. Python爬虫之selenium的使用(八)

    Python爬虫之selenium的使用 一.简介 二.安装 三.使用 一.简介 Selenium 是自动化测试工具.它支持各种浏览器,包括 Chrome,Safari,Firefox 等主流界面式浏 ...

  5. Python爬虫之selenium高级功能

    Python爬虫之selenium高级功能 原文地址 表单操作 元素拖拽 页面切换 弹窗处理 表单操作 表单里面会有文本框.密码框.下拉框.登陆框等. 这些涉及与页面的交互,比如输入.删除.点击等. ...

  6. Python爬虫之selenium库使用详解

    Python爬虫之selenium库使用详解 本章内容如下: 什么是Selenium selenium基本使用 声明浏览器对象 访问页面 查找元素 多个元素查找 元素交互操作 交互动作 执行JavaS ...

  7. selenium自动化 | 借助百度AI开放平台识别验证码登录职教云

    #通过借助百度AI开放平台识别验证码登录职教云 from PIL import Image from aip import AipOcr import unittest # driver.get(zj ...

  8. Python 通过打码平台实现验证码

    在爬虫时,经常遇到登录需要验证码的情况,简单的验证码可以自己解决,复制的验证码需要借助机器学习,有一定的难度.还有一个简单的方案就是采用付费的打码平台. 比如R若快(http://www.ruokua ...

  9. Python爬虫学习笔记之微信宫格验证码的识别(存在问题)

    本节我们将介绍新浪微博宫格验证码的识别.微博宫格验证码是一种新型交互式验证码,每个宫格之间会有一条 指示连线,指示了应该的滑动轨迹.我们要按照滑动轨迹依次从起始宫格滑动到终止宫格,才可以完成验证,如 ...

随机推荐

  1. vue 项目在scope中使用@import引入css ,作用域是全局

    有时候引入第三ui插件,修改样式 时候,需要再单独定义style标签,才有效果,可是会影响全局影响全局,如下所示 加上/deep/,就可以了,

  2. python_3_字符串

    1.strip,lstrip,rstrip " hi, ming ".strip() #去掉前后空格 "@hi,ming@".strip("@&quo ...

  3. 染色dp(确定一行就可行)

    题:https://codeforces.com/contest/1027/problem/E 题意:给定n*n的方格,可以染黑白,要求相邻俩行”完全“不同或完全相同,对于列也是一样.然后限制不能拥有 ...

  4. Spring Cloud服务消费者(rest+ribbon)

    在上一篇文章,讲了服务的注册和发现.在微服务架构中,业务都会被拆分成一个独立的服务,服务与服务的通讯是基于http restful的.Spring cloud有两种服务调用方式,一种是ribbon+r ...

  5. 各大厂RTSP取流的URI

    目前使用过的各大厂商取流规则是在实际的工作中遇到的相关视频接入问题,通过rtsp协议接入视频数据的一些记录,其中的图片可能来源于网络,内容部分来源于网络,本人仅仅是对相关内容作了汇总. 海康RTSP取 ...

  6. 感觉自己out了

    看了公司混乱而落后的框架,想自己开发一个. 无意中到开源网站看到,开源的控件已经非常多了,基本上说应有尽有. 感叹这个知识大爆炸的年代. 自己现在是坐在井底的蛤蟆?

  7. 依赖注入&控制反转

    IoC——Inversion of Control  控制反转DI——Dependency Injection   依赖注入 要想理解上面两个概念,就必须搞清楚如下的问题: 参与者都有谁? 依赖:谁依 ...

  8. [LC] 76. Minimum Window Substring

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  9. LeetCode No.73,74,75

    No.73 SetZeroes 矩阵置零 题目 给定一个 m x n 的矩阵,如果一个元素为 0,则将其所在行和列的所有元素都设为 0.请使用原地算法. 示例 输入: [   [1,1,1],   [ ...

  10. python代码覆盖率统计-coverage

    coverage.py是一个用来统计python程序代码覆盖率的工具.它使用起来非常简单,并且支持最终生成界面友好的html报告.在最新版本中,还提供了分支覆盖的功能. 官方网站: http://ne ...