How to download a webpage that require username and password?

前端 未结 3 876
情歌与酒
情歌与酒 2021-01-07 04:53

For example, I want to download this page after inserting username and password:

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

I have tryed with wget but doe

3条回答
  •  感情败类
    2021-01-07 05:39

    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 johnconnor" in response:
        print "Logged in!"
    

提交回复
热议问题