本帖最后由 1q23w31 于 2021-8-8 08:36 编辑
#其中yanzheng函数返回的是str类型的验证码
import requests
from yanzheng import yanzhengget
from lxml import etree
#分装识别图片
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}
url='https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx'
session = requests.Session()
response1=session.get(url,headers=headers).text
tree=etree.HTML(response1)
image_url = 'https://so.gushiwen.cn'+tree.xpath('//*[@id="imgCode"]/@src')[0]
image=session.get(image_url,headers=headers).content
#保存了验证码图片
with open('./yanzheng.jpg','wb')as f:
f.write(image)
thecode = yanzhengget('./yanzheng.jpg',1902)
thecode = input("验证码:")data={
'__VIEWSTATE':'yy1mHtq84x6Uv/cSRZnkq90uDVg5JsYyXUgjqu5FE7vfcm840Lc306owopK6yka/wK3YaBFAst6KglZLwbJrUy1DqlOuobS/OzxznhO50shQmbg19s0MqqquYh4=',
'__VIEWSTATEGENERATOR':'C93BE1AE',
'from':'http://so.gushiwen.cn/user/collect.aspx',
'email':'334026394@qq.com',
'pwd':'qw123456',
'code':thecode,
'denglu':'登录'
}
url='https://so.gushiwen.cn/user/login.aspx?from=http%3a%2f%2fso.gushiwen.cn%2fuser%2fcollect.aspx'
print(thecode)
response=session.post(url,data,headers=headers).text
with open('古诗.html','w',encoding='utf-8')as f:
f.write(response)
测试过了,你给的密码错的,没有问题
|