2010-11-25 127 views
2

例如,我想將用戶名和密碼後,下載此頁:如何下載需要用戶名和密碼的網頁?

http://forum.ubuntu-it.org/ 

我與wget的tryed,但不起作用。

python是否有解決方案?

你可以用這些用戶名和密碼進行測試:

username: johnconnor 
password: hellohello 
+1

[wget的身份驗證]的可能重複(http://stackoverflow.com/questions/4272770/wget-with-authentication) – Gareth 2010-11-25 10:33:28

+0

複製所有這些的:HTTP ://stackoverflow.com/search?q =%5Bpython%5D + urllib2 +表單搜索幫助。用它。 – 2010-11-25 12:37:12

+0

[Python驗證與urllib2]可能重複(http://stackoverflow.com/questions/1014570/python-authentication-with-urllib2) – 2010-11-25 12:38:44

回答

1

像@robert說的,使用機械化。

爲了讓你開始:

from mechanize import Browser 
b = Browser() 
b.open("http://forum.ubuntu-it.org/index.php") 
b.select_form(nr=0) 
b["user"] = "johnconnor" 
b["passwrd"] = "hellohello" 
b.submit() 

response = b.response().read() 
if "Salve <b>johnconnor</b>" in response: 
    print "Logged in!" 
2

嘗試mechanize模塊。它基本上是一個編程式瀏覽器界面。

2

您可以使用urllib2模塊,並且可以使用基本和基於表單的身份驗證(使用Cookie支持)。

這是一個很好的tutorial在您的問題。

相關問題