提交网络表单 python

发布于 2024-10-21 21:20:32 字数 898 浏览 5 评论 0原文

我正在尝试提交此网络表单并登录此网站: https://www.kalahari.net/profile/pipeline/signin.aspx

脚本完成后,我不断将登录站点的源代码作为输出,所以看起来一切正常(没有错误),但它只是没有登录。我找不到我做错了什么。请帮忙。 我正在使用 Python 3.1.2,我无法使用 Mechanize,因为代码需要用 Python 3.x 编写

我认为我的问题可能是我将登录信息发布到的 POST url,但我似乎无法弄清楚出来,以及它应该是什么。

f=open("page_src.html",'wb') 
cj=cookiejar.CookieJar()

params=urllib.parse.urlencode({'ctl00$ctl00$cplhMain$cplhContent$txtEmail': 'username', 'ctl00$ctl00$cplhMain$cplhContent$txtPassword': 'pass'})

opener = req.build_opener(req.HTTPCookieProcessor(cj))
opener = urllib.request.FancyURLopener()
page = opener.open("https://www.kalahari.net/profile/pipeline/signin.aspx", params)

profilepage = opener.open("https://www.kalahari.net/profile/pipeline/profile.aspx")
source=profilepage.read()

f.write(source)
f.close()

I am trying to submit this webform and log into this site:
https://www.kalahari.net/profile/pipeline/signin.aspx

I keep getting the login site's source code as output when the script is done,so it seems like all is working (no errors) but it's just not logging in. I can't find what I am doing wrong.Please help.
I am using Python 3.1.2, I can't use Mechanize as the code needs to be written in Python 3.x

I think my problem might be the POST url I am posting the login information to, but I cant seem to figure it out, and what it should be.

f=open("page_src.html",'wb') 
cj=cookiejar.CookieJar()

params=urllib.parse.urlencode({'ctl00$ctl00$cplhMain$cplhContent$txtEmail': 'username', 'ctl00$ctl00$cplhMain$cplhContent$txtPassword': 'pass'})

opener = req.build_opener(req.HTTPCookieProcessor(cj))
opener = urllib.request.FancyURLopener()
page = opener.open("https://www.kalahari.net/profile/pipeline/signin.aspx", params)

profilepage = opener.open("https://www.kalahari.net/profile/pipeline/profile.aspx")
source=profilepage.read()

f.write(source)
f.close()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素衣风尘叹 2024-10-28 21:20:32

该网站可能使用 cookie 进行登录,因此您也必须这样做。这意味着您必须保存登录时获得的 cookie,并通过以下每个请求将它们发送到网站。

查看 http.cookiejar

The site is probably using cookies for the login, so you must too. That means you must save the cookies you get when you log in and send them to the site with each following request.

Check out http.cookiejar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文