Python之超级鹰处理验证码
Python之超级鹰处理验证码
登录网站为:
研究生教育信息管理系统
main里是主要内容
其他部分为超级鹰官网提供
传入用户名,密码,及软件id
import requests
from hashlib import md5
from selenium.webdriver import Chrome
import time
from selenium.webdriver import ActionChains
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__':
web = Chrome()
web.get('https://202.199.113.11/login.html')
web.maximize_window()
web.find_element_by_xpath('//*[@id="details-button"]').click()
web.find_element_by_xpath('//*[@id="proceed-link"]').click()
web.find_element_by_xpath('//*[@id="account"]').send_keys('用户名')
web.find_element_by_xpath('//*[@id="pwd"]').send_keys('密码')
img=web.find_element_by_xpath('//*[@id="VerifyCode"]').screenshot_as_png
# 处理验证码
chaojiying = Chaojiying_Client('13841055783', 's88347611487561', '923221') #用户中心>>软件ID 生成一个替换 96001
security_code=chaojiying.PostPic(img, 1902)
print(security_code)
web.find_element_by_xpath('//*[@id="code"]').send_keys(security_code['pic_str'])
web.find_element_by_xpath('//*[@id="login_btn"]').click()

浙公网安备 33010602011771号