准备
注意 前两个参数可在首页源码中搜索到
import requests
import yzm
from lxml import etreesession=requests.Session() #创建session对象headers={'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36'
}url='.aspx?from=.aspx'
page_text(url=url,headers=headers).content
tree=etree.HTML(page_text)
code_img_src=''+tree.xpath('//*[@id="imgCode"]/@src')[0]
img_data(url=code_img_src,headers=headers).content
with open('./code.jpg','wb')as fp:fp.write(img_data)
code_text_code('code.jpg',1004)
code0=code_text['pic_str']
print(code0)#识别结果为:
# {'err_no': 0, 'err_str': 'OK', 'pic_id': '8170914228036700005', 'pic_str': 'e3ws', 'md5': '57a53436632876e16c8fca496705b07a'}
__VIEWSTATE = tree.xpath('//*[@id="__VIEWSTATE"]/@value')[0]
__VIEWSTATEGENERATOR = tree.xpath('//*[@id="__VIEWSTATEGENERATOR"]/@value')[0]
data={'__VIEWSTATE':__VIEWSTATE,'__VIEWSTATEGENERATOR':__VIEWSTATEGENERATOR,'from':'.aspx','email':'你的登录号码','pwd':'你的密码','code':code0,'denglu':'登录'
}
response=session.post(url=url,headers=headers,data=data)
print(response.status_code)# 考虑1:动态变化的请求参数
# 通常会隐藏在当前对应的前端页面的代码中detail_url='.aspx?from=http%3a%2f%2fso.gushiwen%2fuser%2fcollect.aspx'
detail_page_text = session.post(url=detail_url,headers=headers,data=data).text
with open('a.html','w',encoding='utf-8') as fp:fp.write(detail_page_text)
本文发布于:2024-02-03 01:10:39,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170689384147661.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |