Python2.7爬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")
请求头和原始请求保持一致 然后再试试 你这很多header都没传
python代码没缩进 发出来气我们吗
玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/wenda/wd19483.html
相关文章 Recommend
- • scrapy爬取list中所有项,只爬一个就结束了什么原因
- • python2.7运行报Backup FAILED错误是什么问题
- • 我的网站爬虫python代码为什么不能正常运行,哪里
- • python2.7函数删除一个全局变量为什么不报SyntaxE
- • python运行爬虫程序时间如何控制?
- • ubuntu卸载python2.7再重装的问题
- • python2.7配Django1.4GAE方面需要做什么调整
- • Mac python2.7.3创建虚拟环境提示ImportError: No module
- • python爬虫脚通过web控制起始暂停的方法
- • 求CentOS中安装Python-PIP exec: python2.7: not found问题解
- • Discuz scrapy模拟登录Python源码如何写
- • python爬虫运行一段时间后,返回403 forbidden原因是什
您现在的位置: 玩蛇网首页 > Python问题解答 > 正文内容
我要分享到:
必知PYTHON教程 Must Know PYTHON Tutorials
- • python 解释器
- • python idle
- • python dir函数
- • python 数据类型
- • python type函数
- • python 字符串
- • python 整型数字
- • python 列表
- • python 元组
- • python 字典
- • python 集合
- • python 变量
- • python print
- • python 函数
- • python 类定义
- • python import
- • python help
- • python open
- • python 异常处理
- • python 注释
- • python continue
- • python pass
- • python return
- • python global
- • python assert
- • python if语句
- • python break
- • python for循环
- • python while循环
- • python else/elif
- • lambda匿名函数
必知PYTHON模块 Must Know PYTHON Modules
- • os 模块
- • sys 模块
- • re 正则表达式
- • time 日期时间
- • pickle 持久化
- • random 随机
- • csv 模块
- • logging 日志
- • socket网络通信
- • json模块
- • urlparse 解析URL
- • urllib 模块
- • urllib2 模块
- • robotparser 解析
- • Cookie 模块
- • smtplib 邮件
- • Base64 编码
- • xmlrpclib客户端
- • string 文本
- • Queue 线程安全
- • math数学计算
- • linecache缓存
- • threading多线程
- • sqlite3数据库
- • gzip压缩解压
最新内容 NEWS
- • django app提供pv信息的方法是什么
- • Django项目版本升级如何操作?
- • django较多数据传递如何优雅的呈现
- • django1.7获取参数问题求助
- • Django1.7使用内置comment遇到问题
- • python mysql数据库做insert操作时报_mysql_ex
- • 关于python mysql的duplicate insert机制的疑问
- • pymongo使用insert函数批量插入被中断要怎么
- • Python程序员解决棘手问题的常用库
- • 求助关于restfull api接口几个问题
图文精华 RECOMMEND
-
django1.7获取参数问题求助
-
Python程序员解决棘手问题的常用库
-
求问str()同__str__原理上有什么不同
-
scrapy框架里面用link extractor怎么能
-
python {}.fromkeys创建字典append添加操
-
python3 类型Type str doesn't support th
热点文章 HOT
- 学习Python有什么好的书籍推荐?
- Python匿名函数 Lambda表达式作用
- Python与Java、C、Ruby、PHP等编程语言有什么
- Python 正则中文网页字符串提取问题
- 如何为实时性应用存取经纬度?django my
- 想用python做个客户端,在二维码登录这个地
- 有让IDE可识别Python函数参数类型的方法吗
- Python字符串转换成列表正则疑问