用python如何向一个论坛post用户名和密码???

用python如何向一个论坛post用户名和密码???

大家好,我要进入一个论坛,用python如何向一个论坛post用户名和密码???
然后把进到论坛的信息打印出来,在邮件列表谈过这个问题,但没有答案,其中一个别人的例子如下,但是取的数据是没有POST参数的结果!请大家回复,谢谢!!!!
#!/usr/bin/python

import urllib
import urllib2
import cookielib

TARGET = 'http://www.gnhome.com/login.asp'
USERID = 'username'
USERNAME = 'abc123'
PASSWDID = 'password'
PASSWORD = 'abc123'

def main():

    authinfo = urllib2.HTTPBasicAuthHandler()
    cookie = cookielib.CookieJar()
    cp = urllib2.HTTPCookieProcessor( cookie )
   
    opener = urllib2.build_opener( cp )
    urllib2.install_opener ( opener )

    line = urllib.urlencode( { USERID : USERNAME , PASSWDID : PASSWORD } )
    response = urllib2.urlopen( TARGET, line )
    lines = response.read()
    print lines

    f = open( "pagecode.txt", "w" )
    for line in lines:
        f.write( line )
    f.close()
   
    response.close()

main()

http://www.gnhome.com/index.asp?username=aa?passwd=aaa
是不是应该这样?
试试twill模块;
试试twill模块;
还没有用过,还请详细说明一下,谢谢!
'http://www.gnhome.com/index.asp'

这个地址接受你post吗?你怎么不分析就乱写程序阿
还没有解决这个问题,请会的回一下
如果你的地址接受post

[Copy to clipboard] [ - ]
CODE:
import urllib, urllib2, cookielib

site = 'http://www.gnhome.com'
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

params = {USERID:USERNAME, PASSWDID:PASSWORD}
data = urllib.urlencode(params)
req = urllib2.Request(site + '/login.asp', data)
f = opener.open(req)

for line in f.readlines():
  print line

f.close()