+ -
当前位置:首页 → 问答吧 → 人傻,分多,速来!写了个自动登录论坛的脚本,但就是上不去。求教。

人傻,分多,速来!写了个自动登录论坛的脚本,但就是上不去。求教。

时间:2011-05-22

来源:互联网

Python code
import  sys,re,urllib2,urllib,cookielib
def getPageHtml(uri):
   req = urllib2.Request(uri)
   return urllib2.urlopen(req).read()

myCookie = urllib2.HTTPCookieProcessor(cookielib.CookieJar())
openner = urllib2.build_opener(myCookie,urllib2.HTTPHandler)
urllib2.install_opener(openner)

pattern = re.compile('<input type="hidden" name="formhash" value=(.*?) />')
content = getPageHtml('http://bbs.maxpda.com/logging.php?action=login')
formhash = pattern.findall(content)
print formhash
header={'Referer':'http://bbs.maxpda.com/logging.php?action=login&referer=http%3A//bbs.maxpda.com/',
'User-Agent':'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'}
post_data = {'answer':'',
             'formhash':formhash[0],
             'loginfield':'username',
             'password':'yangyang',
             'questionid':'0',
             'referer':'bbs.maxpda.com',
             'username':'咩咩羊'  
             }
print 'logging'
req = urllib2.Request('http://bbs.maxpda.com/logging.php?action=login', urllib.urlencode(post_data),header)
html_src = openner.open(req)
print html_src.geturl()


提交表单里面有个formhash,原理上每次运行得到的值都不一样。但是,我这里天天都是同一个值。

另:
1.用的httpfox,firebug,httpwatch抓包看post参数,初次使用希望高手帮我再抓一遍看看我是不是漏掉了啥?谢谢哈~
2.python网络方面有什么好玩的教材吗?我用python玩的,业余爱好而已。希望推荐下,现在读完了可爱的python,python编程金典,深入理解python。这几本。

最后,非常感谢你们的回复!加油!

作者: hercaffe   发布时间: 2011-05-22

帮帮忙吧~泪奔。

作者: hercaffe   发布时间: 2011-05-23

热门下载

更多