import request
from lxml import etree
from chaojiying import Chaojiying_Client
if __name__ == '__main__':
head = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.46'}
url = 'https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/'
resp_text = requests.get(url, head).text
tree = etree.HTML(resp_text)
contain = tree.xpath('//div/img[@id="imgCode"]/@src')
# print(contain)
# 获取验证码图片地址
img_url = 'https://so.gushiwen.cn/' + contain[0]
resp_img = requests.get(img_url,headers=head).content
# 下载验证码图片到本地
with open("./code.jpg",'wb')as ws:
ws.write(resp_img)
print("success!!!!")
# 调用超级鹰案例代码即可
chaojiying_one = Chaojiying_Client('481429427', 'zdc250.1', '953676') # 用户中心>>软件ID 生成一个替换 96001
im = open('./code.jpg', 'rb').read() # 本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
print(chaojiying_one.PostPic(im, 1902))
成功实现图