打开 网易盾 http://dun.163.com/trial/picture-click  ——在线体验——图中点选

打码平台 ——超级鹰    http://www.chaojiying.com/

网易盾  抓取验证码图片

# -*- coding: utf-8 -*-
# 斌彬电脑
# @Time : 2018/9/13 0013 5:27 from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains # 动作链
from selenium.webdriver.common.by import By
import requests,re
from PIL import Image
from io import BytesIO # 不写入磁盘,显示图片文件
import time from chao_ji_yin import Chaojiying_Client # 超级鹰 class WanYy():
def __init__(self, user, pas):
# 浏览器参数
self.user = user
self.pas = pas
options = Options()
options.add_argument('--window-size=1366,768')
self.dri = webdriver.Chrome(chrome_options=options)
self.wait = WebDriverWait(self.dri, 10) def get_start(self):
# 请求网页
self.dri.get('http://dun.163.com/trial/picture-click')
# 下拉页面
self.dri.execute_script('window.scrollTo(0, 500)') def get_image(self):
# 点击按键,显示验证码
# 获取验证码 图片
self.wait.until(EC.presence_of_element_located((By.XPATH, '/html/body/main/div/div/div[2]/div[2]/div[2]/div/div[2]/div[3]/div/div/div[2]/div[3]/span[2]'))).click()
# 等待加载完成 截图
# time.sleep(2)
# 验证码位置
im = self.wait.until(EC.visibility_of_element_located((
By.XPATH, '/html/body/main/div/div/div[2]/div[2]/div[2]/div/div[2]/div[3]/div/div/div[1]/div/div[1]/img[1]'
))) # 异步 比 time.sleep 好
im1 = BytesIO(self.dri.get_screenshot_as_png())
# Image.open(im).show()
im2 = Image.open(im1)
# 浏览器的左上角坐标 -500 因为下滑了500,
window_im = im2.crop((im.location['x'], im.location['y']-500,im.location['x']+310, im.location['y']+210-500))
# window_im.show()
im_data = BytesIO()
window_im.save(im_data, format('png'))
# 返回图片 二进制 数据
return im_data.getvalue() # 调用超级鹰 识别验证码
def post_validation_participation(self,im_data ):
# 实例化 超级鹰
chao = Chaojiying_Client(self.user, self.pas, '897271')
data = chao.PostPic(im_data, '9103') # 超级鹰反回的 json 数据
data = data.get('pic_str')
data_list = [i.split(',') for i in data.split('|')] # 验证码图片上第个字的坐标
# print(data_list)
return data_list # 得到位置信息,进行点击
def click_word(self, data_list):
# 验证码位置 ,节点
im = self.wait.until(EC.visibility_of_element_located((
By.XPATH, '/html/body/main/div/div/div[2]/div[2]/div[2]/div/div[2]/div[3]/div/div/div[1]/div/div[1]/img[1]'
)))
# 根据节点移动鼠标
# 移到第一个字位置
ActionChains(self.dri).move_to_element_with_offset(im,int(data_list[0][0]), int(data_list[0][1])).perform()
# 点击
ActionChains(self.dri).click().perform()
time.sleep(1) # 移到第二个字位置
ActionChains(self.dri).move_to_element_with_offset(im,int(data_list[1][0]), int(data_list[1][1])).perform()
# 点击
ActionChains(self.dri).click().perform()
time.sleep(1) # 移到第三个字位置
ActionChains(self.dri).move_to_element_with_offset(im,int(data_list[2][0]), int(data_list[2][1])).perform()
# 点击
ActionChains(self.dri).click().perform() # 灰像函数一样调用
def __call__(self, *args, **kwargs):
self.get_start()
imdata = self.get_image()
da_list = self.post_validation_participation(imdata)
print(da_list)
self.click_word(da_list)
# time.sleep(5)
# self.dri.close() if __name__ == '__main__':
yedun = WanYy('超级鹰账号', '密码')
yedun()

  

超级鹰  验证码读取

# -*- coding: utf-8 -*-
# 斌彬电脑
# @Time : 2018/9/13 0013 5:04 #!/usr/bin/env python
# coding:utf-8 import requests
from hashlib import md5 class Chaojiying_Client(object): def __init__(self, username, password, soft_id):
self.username = username
password = password.encode('utf8')
self.password = md5(password).hexdigest()
self.soft_id = soft_id
self.base_params = {
'user': self.username,
'pass2': self.password,
'softid': self.soft_id,
}
self.headers = {
'Connection': 'Keep-Alive',
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
} def PostPic(self, im, codetype):
"""
im: 图片字节
codetype: 题目类型 参考 http://www.chaojiying.com/price.html
"""
params = {
'codetype': codetype,
}
params.update(self.base_params)
files = {'userfile': ('ccc.jpg', im)}
r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files, headers=self.headers)
return r.json() def ReportError(self, im_id):
"""
im_id:报错题目的图片ID
"""
params = {
'id': im_id,
}
params.update(self.base_params)
r = requests.post('http://upload.chaojiying.net/Upload/ReportError.php', data=params, headers=self.headers)
return r.json() if __name__ == '__main__':
chaojiying = Chaojiying_Client(账号, 密码, '897271')
#用户中心>>软件ID 生成一个替换 96001
im = open('a.jpg', 'rb').read()
#本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
print(chaojiying) .PostPic(im, 1902)
#1902 验证码类型 官方网站>>价格体系 3.4+版 print 后要加()

  

潭州课堂25班:Ph201805201 爬虫基础 第十一课 点触验证码 (课堂笔记)的更多相关文章

  1. 潭州课堂25班:Ph201805201 爬虫基础 第八课 selenium (课堂笔记)

    Selenium笔记(1)安装和简单使用 简介 Selenium是一个用于Web应用程序测试的工具. Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE(7, 8, ...

  2. 潭州课堂25班:Ph201805201 爬虫基础 第三课 urllib (课堂笔记)

    Python网络请求urllib和urllib3详解   urllib是Python中请求url连接的官方标准库,在Python2中主要为urllib和urllib2,在Python3中整合成了url ...

  3. 潭州课堂25班:Ph201805201 爬虫基础 第六课 选择器 (课堂笔记)

    HTML解析库BeautifulSoup4 BeautifulSoup 是一个可以从HTML或XML文件中提取数据的Python库,它的使用方式相对于正则来说更加的简单方便,常常能够节省我们大量的时间 ...

  4. 潭州课堂25班:Ph201805201 爬虫基础 第十三课 cookie (课堂笔记)

    # -*- coding: utf-8 -*- # 斌彬电脑 # @Time : 2018/9/15 0015 4:52 #cookie 是服务器发给浏览器的特殊信息 # 可以理解为一个临时通行证 # ...

  5. 潭州课堂25班:Ph201805201 爬虫基础 第十课 图像处理- 极验验证码 (课堂笔记)

    用 python 的  selenium  访问  https://www.huxiu.com/ 自动通过验证码 # -*- coding: utf-8 -*- # 斌彬电脑 # @Time : 20 ...

  6. 潭州课堂25班:Ph201805201 爬虫基础 第七课 Python与常见加密方式 (课堂笔记)

    打开图形界面  18版 Python与常见加密方式 前言 我们所说的加密方式,都是对二进制编码的格式进行加密的,对应到Python中,则是我们的Bytes. 所以当我们在Python中进行加密操作的时 ...

  7. 潭州课堂25班:Ph201805201 爬虫基础 第五课 (案例) 豆瓣分析 (课堂笔记)

    动态讲求 , 翻页参数: # -*- coding: utf-8 -*- # 斌彬电脑 # @Time : 2018/9/1 0001 3:44 import requests,json class ...

  8. 潭州课堂25班:Ph201805201 爬虫基础 第四课 Requests (课堂笔记)

    优雅到骨子里的Requests   1528811134432   简介   上一篇文章介绍了Python的网络请求库urllib和urllib3的使用方法,那么,作为同样是网络请求库的Request ...

  9. 潭州课堂25班:Ph201805201 爬虫高级 第十一课 Scrapy-redis分布 项目实战 (课堂笔

随机推荐

  1. 企业环境下的OpenStack自动化功能测试(转载)

    原文地址:http://mp.weixin.qq.com/s?__biz=MzAxOTAzMDEwMA==&mid=2652502581&idx=1&sn=0c26519bcb ...

  2. SharePoint 2010管理中心服务器提示“需要升级”

    共3台服务器,只有管理中心所在服务器提示需要升级: 执行命令:stsadm –o localupgradestatus,返回结果类似如下: [2] content database(s) encoun ...

  3. linux windows 共享文件夹

    1.首先在windows上共享一个目录,如:共享了目录share,用户和密码都是:massky 2.在linux机器上,在/mnt目录下建立一个ml45目录,使用root用户,执行下面命令: moun ...

  4. 007_linux显示一个文件的某几行(中间几行)

    <1>从第3000行开始,显示1000行.即显示3000~3999行 cat -n filename | tail -n +3000 | head -n 1000 cat -n anaco ...

  5. mysql数据库报错:InnoDB: Operating system error number 13 in a file operation

    环境:centos6.5 x86_64 启动mysql发现日志报错(日志路径可以查看/etc/my.cnf的配置) 160722 10:34:08 [Note] Found 42570716 of 4 ...

  6. nagios系列(七)nagios通过自定义脚本的方式监控mysql主从同步

    nagios监控mysql主从同步 起因:nagios可能监控到mysql服务的运行情况,但确不能监控mysql的主从复制是否正常:有时候,同步已经停止,但管理人员却不知道. 登陆mysql从服务器, ...

  7. 转载:2.2 Nginx配置的通用语法《深入理解Nginx》(陶辉)

    原文:https://book.2cto.com/201304/19625.html Nginx的配置文件其实是一个普通的文本文件.下面来看一个简单的例子.user  nobody; worker_p ...

  8. Python-GIL 进程池 线程池

    5.GIL vs 互斥锁(*****) 1.什么是GIL(Global Interpreter Lock) GIL是全局解释器锁,是加到解释器身上的,保护的就是解释器级别的数据 (比如垃圾回收的数据) ...

  9. PYTHON-模块 sys os random shutil

    import sys # 环境变量# print(sys.path)# # 查看已经加载的模块# print(sys.modules)# # 获取终端调用时的参数# print(sys.argv)# ...

  10. url传参中文乱码解决

    url传参request.setCharacterEncoding("utf-8");无法解决中文乱码问题 解决方法: 修改tomcat---conf----server.xml文 ...