标签:with path log 程序 识别 XML 本地 pen open
#!/usr/bin/python
import requests
from lxml import etree
from codeClass import YDMHTTP
#封装识别验证码图片的函数
def getCodeText(imgPath,codeType):
pass
#将验证码下载到本地
headers = {
‘User-Agent‘:‘Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2626.106 Safari/537.36‘
}
url = ‘https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx‘
page_text = requests.get(url=url,headers=headers).text
#解析验证码图片img中的src属性
page_text = etree.HTML(page_text)
code_img_src = ‘https://so.gushiwen.org‘+tree.xpath(‘//*[@id="imgCode"]/@src‘)[0]
img_data = requests.get(url=code_img_src,headers=headers).content
#将验证码图片保存到了本地
with open(‘./code.jpg‘,‘wb‘) as fp:
fp.write(img_data)
#调用打码平台对应程序进行识别
code_text = getCodeText(‘code.jpg‘,1004)
print(‘识别结果为:‘,code_text)
标签:with path log 程序 识别 XML 本地 pen open
原文地址:https://www.cnblogs.com/gerenboke/p/13389041.html