栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python模拟登陆古诗文网手动输入验证码显示验证码错误

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python模拟登陆古诗文网手动输入验证码显示验证码错误

Python模拟登陆古诗文网手动输入验证码显示验证码错误

import requests
from lxml import etree
session=requests.Session()
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36',
    }
url='https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx'
re=requests.get(url=url,headers=headers)
page_text=re.text
print(re.status_code)
print(page_text)
tree=etree.HTML(page_text)
code_image_src='https://so.gushiwen.cn'+tree.xpath('//*[@id="imgCode"]/@src')[0]
print(re.status_code)
#此处要用session请求验证码地址保存cookies后面输入验证码后才不会报错
img_data=session.get(url=code_image_src,headers=headers).content


with open ('./code.jpg','wb',) as fp:
    fp.write(img_data)

stri = input("请输入:")
login_url='https://so.gushiwen.cn/user/login.aspx?from=http%3a%2f%2fso.gushiwen.cn%2fuser%2fcollect.aspx'
data={
'__VIEWSTATE': '/vwC0eOzmbm46rBwBLdueaU67+W8RzMKuEHilr4oCRcLMYJcZqHUZEApf3/nuViOvwzPI2t2hArtxhP3wAGIJ6m+btN2s+2eHJ8MyRCZayIHrnAhyeqzn4JmyNQ=',
'__VIEWSTATEGENERATOR': 'C93BE1AE',
'from': 'http://so.gushiwen.cn/user/collect.aspx',
'email': '17xxxx66827',
'pwd': '2022waxxxxx.',
'code': stri,
'denglu': '登录'

}
login_page_text=session.post(url=login_url,headers=headers,data=data).text
with open ('gushiwen.html','w',encoding='utf-8') as fp:
    fp.write(login_page_text)

获取验证码时需要保存cookie,输入验证码重新请求时才不会出现刷新验证码,验证码错误的情况,最终的网页源码保存在本地,以浏览器形式打开
验证码错误页面

登陆成功后的显示界面:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/822620.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号