Python之超級鷹處理驗證碼
阿新 • • 發佈:2021-10-06
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()