How to download a webpage that require username and password?

大兔子大兔子 提交于 2019-12-01 01:40:14

Like @robert says, use mechanize.

To get you started:

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!"

Try the mechanize module. It's basically a programmatic browser interface.

You can use the urllib2 module and with that it is possible do to basic and form based authentication (with cookies support).

Here is a nice tutorial on your issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!