2010-11-25 131 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在您的问题。

相关问题