python 登陆网站(转)

Posted on 2007-02-06 13:16 小蚂蚁 阅读(452) 评论(0)  编辑  收藏 所属分类: 天国之路

# loginbbs.py
import urllib,httplib
params = urllib.urlencode({'username':'pytest',  #此处为要post的登陆参数,你可以修改为你自己的参数
  'password':'pypassword',
  'Cookies_Time': 1,
 'IsLogin':True})
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
  #构建headers
conn = httplib.HTTPConnection("music.popv.net:80")  #建立http连接,记得地址不要加'http://'且要加上port
conn.request("POST",http://music.popv.net/popv/login.asp, params, headers)
 #发送登陆请求
response = conn.getresponse()  #获得回复
print response.status, response.reason  #获得请求状态
data = response.read()  #获得登陆后的网页内容
conn.close()  #关闭连接


只有注册用户登录后才能发表评论。


网站导航: