获取验证码图片代码
from selenium import webdriver
from PIL import Image
# 第一步: 创建一个浏览器
dirver = webdriver.Chrome()
# 访问登录页面
dirver.get('http://erp.lemfix.com/register.html')
# 第三步:验证码识别
# 保存浏览器当前页面
dirver.save_screenshot("page.png")
# 从页面中截取验证码
vcode = dirver.find_element_by_xpath('//*[@id="verifyCanvas"]')#找到验证码元素
# 1、获取验证码元素上下左右边界左边
loc = vcode.location
size = vcode.size
#子所以*1.25是因为电脑分辨率是125
left = loc['x']*1.25
top = loc['y']*1.25
right = (loc['x'] +size['width'])*1.25
button = (loc['y']+size['height'])*1.25
# 截取页面中的验证码
page_pic = Image.open('page.png')
# 进行截图:参数时一个元组(left,top,right,button)
v_code_pic = page_pic.crop((left,top,right,button))
v_code_pic.save('yzm.png')
超级鹰代码
```python
import requests
from hashlib import md5
class Chaojiying_Client(object):
def __init__(self, username, password, soft_id):
self.username = username
# todo:更改点一
self.password = md5(password.encode("utf-8")).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__':
# todo: 更改点二,输入注册的账号与密码,软件ID--https://www.chaojiying.com/user/mysoft/
chaojiying = Chaojiying_Client('账号', '密码', '软件id')
# todo: 更改点三:本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
im = open('', 'rb').read()
# todo: 更改点四:1902 验证码类型--https://www.chaojiying.com/price.html,在官网测试案例可以查看
print(chaojiying.PostPic(im, 9101))