我这个人工看验证码成功了。import requests
from lxml import etree
import time
def main():
s = requests.session()
headers = {'User-Agent': "Mozilla/5.0"}
url = 'https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx'
r = s.get(url, headers=headers)
tree = etree.HTML(r.text)
__VIEWSTATE = tree.xpath('//input[@id="__VIEWSTATE"]/@value')[0]
__VIEWSTATEGENERATOR = tree.xpath('//input[@id="__VIEWSTATEGENERATOR"]/@value')[0]
result = tree.xpath('//*[@id="imgCode"]/@src')[0]
# 拼接url以后将验证码图片保存到本地
image_url = f'https://so.gushiwen.cn/{result}'
image_data = s.get(image_url, headers=headers).content
with open("./code.jpg", "wb") as fp:
fp.write(image_data)
time.sleep(20)
code = input('Please input code')
data = {
'__VIEWSTATE': __VIEWSTATE,
'__VIEWSTATEGENERATOR': __VIEWSTATEGENERATOR,
'from': 'http',
'email': 'aaaaa',
'pwd': 'bbbbbb',
'code': code,
'denglu': '登录'
}
url = 'https://so.gushiwen.cn/user/login.aspx?from=http%3a%2f%2fso.gushiwen.cn%2fuser%2fcollect.aspx'
r = s.post(url, headers=headers, data=data)
print(r.text)
if __name__ == '__main__':
main()
|