由于ASP..NET的回传页问题,还需要正则匹配出隐藏表单。(由于安全问题,不提供地址)
import requests
import re
r=requests.get("http://q.aspx",cookies=dict(STUID='79'));
'''
import re
relink = '(.*)'
info = 'baidu'
cinfo = re.findall(relink,info)
print cinfo
'''
def funMatchViewState(s):
match1=''
match1re=re.findall(match1,s)
return match1re[0]
def funMatchViewGen(s):
match1='';
match1re=re.findall(match1,s);
return match1re[0]
def funMatchEvent(s):
match1=''
match1re=re.findall(match1,s)
return match1re[0]
viewstate=funMatchViewState(r.text)
viewgen=funMatchViewGen(r.text)
matchevent=funMatchEvent(r.text)
print(viewgen)
print(viewstate)
print(matchevent)
print(r.cookies)
#################################################
data={
'__VIEWSTATE':viewstate,
#'__VIEWSTATEGENERATOR':viewgen,
'__EVENTVALIDATION':matchevent,
'hfid':'79','rblsex':'0','txttell':'8','txtqq':'',
'txtbirthday':'2017-09-13', 'txtage':'990','txthome':'','txtabout':'','txtstuno':''
}
#files = {'FileUpload1': open('1.png', 'rb')}
files = {'FileUpload1': ""}
header={
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding':'gzip, deflate',
'Accept-Language':'zh-CN,zh;q=0.8',
'Cache-Control':'max-age=0',
'Cookie':'STUID=79',
'Connection':'keep-alive',
'Origin':'http://q',
'Referer':'http://q',
'Upgrade-Insecure-Requests':'1',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'
}
r2=requests.post("http://q.aspx",data=data,headers=header)
print(r2)