超级鹰+PyQt4识别验证码

import requests
from lxml import etree
from chaojiying import Chaojiying_Client
import sys
from PyQt4.QtWebKit import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class Render(QWebPage):  # 用来渲染网页,将url中的所有信息加载下来并存到一个新的框架中
    def __init__(self,url):
        self.app = QApplication(sys.argv)
        QWebPage.__init__(self)
        self.loadFinished.connect(self._loadFinished)
        self.mainFrame().load(QUrl(url))
        self.app.exec_()
    def _loadFinished(self, result):
        self.frame = self.mainFrame()
        self.app.quit()


if __name__ == '__main__':
    url="http://hsk.blcu.edu.cn/Login"
    headers={
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4455.2 Safari/537.36"
    }
    #超级鹰
    chaojiying = Chaojiying_Client('zhouchengbin', 'zhchb19419518', '915817')  # 用户中心>>软件ID 生成一个替换 96001

    r=Render(url)
    page_text=r.frame.toHtml()
    tree=etree.HTML(page_text)
    code_img_url="http://hsk.blcu.edu.cn"+tree.xpath('/html/body/div/div[2]/div/div/div/div[1]/form/div[3]/div[2]/img/@src')[0]
    img_code=requests.get(url=code_img_url,headers=headers).content#得到验证码
    chaojiying = Chaojiying_Client('zhouchengbin', 'zhchb19419518', '915817')
    print(chaojiying.PostPic(img_code, 4004).get('pic_str'))

 

posted @ 2021-04-27 16:26  奋进的少年  阅读(111)  评论(0)    收藏  举报