如何下载需要用户名和密码的网页?

发布于 2024-10-04 00:20:44 字数 229 浏览 8 评论 0原文

例如,我想在插入用户名和密码后下载此页面:

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

我已尝试使用 wget 但不起作用。

有 python 的解决方案吗?

您可以使用这些用户名和密码进行测试:

username: johnconnor
password: hellohello

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

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

I have tryed with wget but doesn't work.

Is there a solution with python ?

You can test with these username and password:

username: johnconnor
password: hellohello

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

追风人 2024-10-11 00:20:44

您可以使用 urllib2 模块,这样就可以进行基本和基于表单的身份验证(有 cookie 支持)。

这是关于您的问题的一个很好的教程

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.

海拔太高太耀眼 2024-10-11 00:20:44

就像@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!"

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!"
最近可好 2024-10-11 00:20:44

尝试 mechanize 模块。它基本上是一个编程浏览器界面。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文