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

查看:121
本文介绍了如何使用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')

使用go…浏览到要登录的站点后,就可以使用showforms()列出所有表单.只需在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天全站免登陆