gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 06:22:08 24 4
gpt4 key购买 nike

我是 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()

我检查了登录页面的源代码,它说用户名和密码值是“登录名和密码”,所以我更改了它。我已经尝试了一些可以在这里找到的其他示例,例如 google news feed,它也无法登录 :(

最佳答案

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

<form method="POST" action="http://ryushare.com/" name="FL">

你应该打开()“操作”页面,例如

opener.open('http://ryushare.com/", login_data)
# Now you can interact with site

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 在应用此修复程序后仍然遇到问题。答案是通常有隐藏的表单标签,包括用于提交按钮的 。在您的请求中包含这些标签的数据以及您的用户名和密码。

关于python - 如何使用 python 登录并保存 cookie,然后使用该信息仅查看成员(member)页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11405975/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com