python urllib2 document.login

编程入门 行业动态 更新时间:2024-10-27 04:25:14
本文介绍了python urllib2 document.login的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您将如何使用python urllib2登录到这样设置的网站

How would you go about logging into a website that is set up like so, using python urllib2

以下是表单和onsubmit上的javascript处理程序.我将如何在python中处理此问题?

The below is the javascript handler on the form and a onsubmit. How would I process this in python?

<script> function handleLogin() {document.login.un.value = document.login.username.value;document.login.width.value = screen.width;document.login.height.value = screen.height;} </script>

下面是html表单,其中包含所有要作为帖子发送的组件.使我失望的是onsubmit函数.

Below is the html form with all the components to send as post. What holds me up is the onsubmit function.

<form id='login' name='login' method='post' onsubmit="handleLogin();" action='login.php'> <input class="txtbox glow" type="text" id="username" name="username" value="blanksss"> <input class="txtbox glow" type="password" id="password" name="pw" size="18" autocomplete="off" onkeypress="checkCaps(event)"> <input class="checkbox" type="checkbox" id="rememberUn" name="rememberUn" checked="checked"> <input class="loginButton" type="submit" id="Login" name="Login" value="Login"> </form>

我可以在没有javascript的简单网站上使用的Python代码是:

Python Code I have that works with easy sites without javascript is:

cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) opener.addheaders.append(('User-agent', 'Mozilla/4.0')) opener.addheaders.append( ('Referer', 'login.site/') ) login_data = urllib.urlencode({'username' : 'mylogin', 'pw' : 'mypass', 'Login' : 'Login', 'rememberUn' : 'checked' }) resp = opener.open('login.site/', login_data) website = opener.open('eu1.site/a03/o') bowl = BeautifulSoup(website)

关于如何处理javascript代码然后将完成的结果发布到表单操作的任何想法?

Any thoughts on how to process javascript code then post the finished results to the action of the form?

谢谢

推荐答案

使用请求

import requests data = { "username" : "youruser", "password" : "yourpass", "Login" : "Login", } r = requests.post(url, data=data)

此脚本将在Python 2.7上运行

this Script Will Work On Python 2.7

更多推荐

python urllib2 document.login

本文发布于:2023-10-09 16:52:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1476246.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:python   login   document

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!