我想用Python連接到一個網站,但我不知道該怎麼做。Python幫助:登錄到網站
該網站的HTML看起來像這樣:
<form action="connexion.php" method="post">
User<br />
<input name="login_user" type="text" />
<br />
Password<br />
<input name="pass_word" type="password" />
<br />
<input value="Connexion" type="submit" />
</form>
好吧,我會盡量解釋更好......
這裏是連接到pun_bb論壇腳本:
import urllib
import string
host = "http://punbbforum.example.com"
username = "userxxx"
password = "passwww"
params = {
'req_username' : username,
'req_password' : password,
'form_sent' : 1
}
wclient = urllib.URLopener()
req = wclient.open(host + "/login.php?action=in", urllib.urlencode(params))
info = req.info()
if 'set-cookie' not in info:
sys.exit(-3)
cookie = info['set-cookie']
cookie = cookie[:string.find(cookie, ';')]
wclient.addheader('Cookie', cookie);
req = wclient.open("http://punbbforum.example.com/post.php?fid=15")
print req.read()
但它只適用於punbb網站...我想創建一個腳本,它將與此示例一起工作...
謝謝
你是什麼意思?你的意思是使用python進行服務器端腳本?你想使用python發佈到'connexion.php'嗎? – 2011-03-05 12:43:40
我想訪問我的會員數據,但爲此,我必須輸入我的登錄數據。在這裏,通過python。 – Misterx3 2011-03-05 13:00:15