如何使用 Python 登录网站? [英] How can I login to a website with Python?

查看:42
本文介绍了如何使用 Python 登录网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该怎么做?我试图输入一些指定的链接(使用 urllib),但要这样做,我需要登录.

How can I do it? I was trying to enter some specified link (with urllib), but to do it, I need to log in.

我从网站上获得了这个来源:

I have this source from the site:

<form id="login-form" action="auth/login" method="post">
    <div>
    <!--label for="rememberme">Remember me</label><input type="checkbox" class="remember" checked="checked" name="remember me" /-->
    <label for="email" id="email-label" class="no-js">Email</label>
    <input id="email-email" type="text" name="handle" value="" autocomplete="off" />
    <label for="combination" id="combo-label" class="no-js">Combination</label>
    <input id="password-clear" type="text" value="Combination" autocomplete="off" />
    <input id="password-password" type="password" name="password" value="" autocomplete="off" />
    <input id="sumbitLogin" class="signin" type="submit" value="Sign In" />

这可能吗?

推荐答案

也许你想使用 twill.它非常易于使用,应该能够做您想做的事情.

Maybe you want to use twill. It's quite easy to use and should be able to do what you want.

它将如下所示:

from twill.commands import *
go('http://example.org')

fv("1", "email-email", "blabla.com")
fv("1", "password-clear", "testpass")

submit('0')

您可以使用 showforms() 列出所有表单,一旦您使用 go... 浏览到您要登录的站点.只需从 python 解释器中尝试即可.

You can use showforms() to list all forms once you used go… to browse to the site you want to login. Just try it from the python interpreter.

这篇关于如何使用 Python 登录网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆