python爬校园网(Discuz)模拟表单提交遇见的问题
我用的是python2.7,学校校园网用的DIscyz框架,通过浏览器登录,给别人留言抓包,如图
以下是捕获的我自己程序发的包
但是程序post的结果是返回了
请菊苣们看看是哪错了...
附上代码如下:
#coding:utf-8import urllib,urllib2,cookielib,sys,random,re
reload(sys)
sys.setdefaultencoding('utf8')
url="http://rs.xidian.edu.cn/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1"
value={"cookietime":"2592000","username":"柒染","password":"e2fa0937aa136df5818418d9a5c31fc4","quickforward":"yes","handlekey":"ls"}
data=urllib.urlencode(value)
headers={"Referer":"http://rs.xidian.edu.cn/forum.php?mod=viewthread&tid=642692","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.78.2 (KHTML, like Gecko) Version/7.0.6 Safari/537.78.2"}
req=urllib2.Request(url=url,data=data,headers=headers)
cj=cookielib.CookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
response=opener.open(req)#登陆成功
def shuitie(opener,url,timelate,pagenumber,message):
judege=True
data={"message":message,"posttime":"1409033841","formhash":"9571e29b","usesig":"1","subject":" "}
data=urllib.urlencode(data)
print data
alltitle=[]
while(judege):
number=random.randint(646,5000)
number=2692
url_open=url+"64"+str(number)
response=opener.open(url_open).read().encode("utf-8")
fid=re.findall("ptm\s*pnpost.*?fid=(\d*)",response,re.S)#获取当前页面的fid
if(len(fid)==1):
fid=fid[0]
else:
continue
tid="64"+str(number)
requestURL="http://rs.xidian.edu.cn/forum.php?mod=post&action=reply&fid="+fid+"&tid="+tid+"&extra=&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1"
req=urllib2.Request(headers=headers,url=requestURL,data=data)
response=opener.open(req).read().encode("utf-8")
title=re.findall("<title>(.*?)</title>",response,re.S)#title
if(len(title)==1):
alltitle.append(title[0])
print fid
judege=False
print(alltitle[0])
shuitie(opener,"http://rs.xidian.edu.cn/forum.php?mod=viewthread&tid=",11,1,"MARK,下下来看看..")
the_page=response.read().decode("utf-8")
回答:
请求头和原始请求保持一致 然后再试试 你这很多header都没传
python代码没缩进 发出来气我们吗
以上是 python爬校园网(Discuz)模拟表单提交遇见的问题 的全部内容, 来源链接: utcz.com/a/160481.html