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. Codeforces Round #606 E

    题:https://codeforces.com/contest/1277/problem/E 题意:给定无向图,求有多少个pair之间的简单路径一定要经过给定的点a和b(pair中任何一个都不是a或 ...

  2. P1010 幂次方 P1022 计算器的改良

    P1010 幂次方 一.题目 https://www.luogu.org/problemnew/show/P1010 二.代码 #include<bits/stdc++.h> using ...

  3. LoadRunner 工具使用

    LoaderRunner 第一天 1.1 性能测试基础 ​ 服务器端性能测试 1.1 什么是性能测试的本质 基于协议模拟用户发出请求(业务的模拟), 对服务器形成一定的负载,来测试服务器的性能指标是否 ...

  4. selenium登录网银,密码控件输入

    尝试登录农行网银,发现带控件的密码输入框怎么都无法输入啊 最后用虚拟键盘实现的  , DD模拟键盘 http://www.ddxoft.com/ 图形验证码识别没过,有时间再继续 需要安装  Tess ...

  5. linux_nano命令

    nano是一个字符终端的文本编辑器,有点像DOS下的editor程序.它比vi/vim要简单得多,比较适合Linux初学者使用.某些Linux发行版的默认编辑器就是nano. nano命令可以打开指定 ...

  6. python语法基础-并发编程-协程-长期维护

    ###############    协程    ############## # 协程 # 小知识点, # 协程和进程和线程一样都是实现并发的手段, # 开启一个线程,创建一个线程,还是需要开销, ...

  7. layui从url中取值 ajax获取当前链接中的变量

    在使用layui(javascript)的时候,  需要从当前页面的url地址中取值, 例如: http://localhost:8081/html/fund-purchase.html?fundID ...

  8. SMTP错误码/建议解决方法

    SMTP错误码/建议解决方法 错误总表 420 1. Timeout Communication Problem Encountered During Transmission. Thie Is a ...

  9. Leetcode1_两数之和

    题目 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数组中同 ...

  10. 作业:for循环,迭代法和穷举法

                                                    for()循环 四要素:初始条件,循环条件,状态改变,循环体. 执行过程:初始条件--循环条件--循环体 ...