如何使用python登录并保存cookie,然后使用该信息仅为成员查看页面

2024-10-02 18:16:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我对python相当陌生,正在尝试编写一个脚本来登录位于http://ryushare.com/login.python的页面。在

我尝试了很多次,但都没能登录,我不知道为什么。 登录到页面后,我希望得到http://ryushare.com/file-manager.python的返回

下面是我试图通过阅读其他人的示例来尝试的代码。在

import urllib, urllib2, cookielib
username = 'myusername'
password = 'mypassword'

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_data = urllib.urlencode({'login' : username, 'password' : password})
opener.open('http://www.ryushare.com/login.python', login_data)
resp = opener.open('http://ryushare.com/file-manager.python')
print resp.read()

我检查了登录页面的源代码,上面说用户名和密码值是“login and password”,所以我修改了它。 我已经尝试了一些其他的例子,可以在这里找到像谷歌新闻feed,它也无法登录:(


Tags: comhttpdatausernamemanagerloginpassword页面
1条回答
网友
1楼 · 发布于 2024-10-02 18:16:33

在页面源代码中,我们有以下HTML:

^{1}$

你应该打开“动作”页面,例如

^{pr2}$

http://www.w3schools.com/html/html_forms.asp

Submit Button

<input type="submit" /> defines a submit button.

A submit button is used to send form data to a server. The data is sent to the page specified in the form's action attribute. The file defined in the action attribute usually does something with the received input:

<form name="input" action="html_form_action.asp" method="get">
Username: <input type="text" name="user" /> <input type="submit"
value="Submit" /> </form>

How the HTML code above looks in a browser:

Username: (Entry box)

If you type some characters in the text field above, and click the "Submit" button, the browser will send your input to a page called "html_form_action.asp". The page will show you the received input.

编辑:其他表单数据

从评论中可以看出,在应用了这个修复程序之后,OP仍然有问题。答案是,通常有隐藏的表单标记,包括提交按钮的。在您的请求中包括这些标签的数据以及您的用户名和密码。在

相关问题 更多 >