Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将密码输入网页表单并在Python中发布?_Python_Urllib2_Urllib - Fatal编程技术网

如何将密码输入网页表单并在Python中发布?

如何将密码输入网页表单并在Python中发布?,python,urllib2,urllib,Python,Urllib2,Urllib,我正在尝试登录到一个非常简单的web界面。这应包括输入和提交密码;我不希望需要跟踪cookies,也没有用户名 该网页如下图所示,带有用于发布密码的简单表单: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!-- saved from url=(0039)http://start.ubuntu.com/wless/index.php --> <html><head>

我正在尝试登录到一个非常简单的web界面。这应包括输入和提交密码;我不希望需要跟踪cookies,也没有用户名

该网页如下图所示,带有用于发布密码的简单表单:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- saved from url=(0039)http://start.ubuntu.com/wless/index.php -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Wireless Authorisation Page</title>
</head>

<body>
<h1>Title</h1>
<h2>Wireless Access Authorisation Page</h2>

Hello<br>
<form action="http://start.ubuntu.com/wless/index.php" method="POST"><input type="hidden" name="action" value="auth">PIN: <input type="password" name="pin" size="6"><br><input type="submit" value="Register"></form>
<h3>Terms of use</h3><p>some text</p>

</body>
</html>

这不起作用(返回同一页面,登录不成功)。我哪里会出错?

您可能想尝试使用类似

这允许您

import requests
print(requests.post(url, data={"password": "verysecretpasscode"}))

表单有两个命名输入字段,您只发送一个:

<form action="http://start.ubuntu.com/wless/index.php" method="POST">
         <input type="hidden" name="action" value="auth">
    PIN: <input type="password" name="pin" size="6"><br>
         <input type="submit" value="Register">
</form>

@谢谢你的建议。硒对这项任务来说似乎是杀伤力过大。我真的不想突然打开一个完整的浏览器,因为真正需要的是一个后台的wee守护进程。请求应该是您的“转到”模块。在这种情况下,“这没有起作用”是对您的问题的完全无用的描述。@Brunodesshuilliers抱歉,我添加了更多细节。当我说它没有工作时,我的意思是相同的页面被返回并且登录不成功。谢谢你的建议。我试过了,但似乎不起作用。我收到一个回复200,然后返回了相同的网页,但登录不成功。非常感谢你对问题的解释。
<form action="http://start.ubuntu.com/wless/index.php" method="POST">
         <input type="hidden" name="action" value="auth">
    PIN: <input type="password" name="pin" size="6"><br>
         <input type="submit" value="Register">
</form>
{"pin": "verysecretpasscode", "action": "auth"}