python 登陸網(wǎng)站(轉(zhuǎn))
Posted on 2007-02-06 13:16 小螞蟻 閱讀(469) 評(píng)論(0) 編輯 收藏 所屬分類: 天國(guó)之路# loginbbs.py
import urllib,httplib
params = urllib.urlencode({'username':'pytest',? #此處為要post的登陸參數(shù),你可以修改為你自己的參數(shù)
? 'password':'pypassword',
? 'Cookies_Time': 1,
?'IsLogin':True})
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
? #構(gòu)建headers
conn = httplib.HTTPConnection("music.popv.net:80")? #建立http連接,記得地址不要加'http://'且要加上port
conn.request("POST",http://music.popv.net/popv/login.asp, params, headers)
?#發(fā)送登陸請(qǐng)求
response = conn.getresponse()? #獲得回復(fù)
print response.status, response.reason? #獲得請(qǐng)求狀態(tài)
data = response.read()? #獲得登陸后的網(wǎng)頁內(nèi)容
conn.close()? #關(guān)閉連接