Home  >  Q&A  >  body text

python爬校园网(Discuz)模拟表单提交遇见的问题

我用的是python2.7,学校校园网用的DIscyz框架,通过浏览器登录,给别人留言抓包,如图


以下是捕获的我自己程序发的包


但是程序post的结果是返回了

请菊苣们看看是哪错了...
附上代码如下:

#coding:utf-8
import 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")
天蓬老师天蓬老师2742 days ago1016

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-04-17 13:25:55

    Keep the request headers consistent with the original request and try again. You didn’t pass many headers
    The python code is not indented. Is it annoying us?

    reply
    0
  • Cancelreply