Re: [问题] 该怎么用python登入自己写的表单?

楼主: Neisseria (Neisseria)   2016-04-13 12:27:19
※ 引述《phpjson (php er)》之铭言:
: 大家好
: 新手在下 写了一个测试网页 位在 http://pure.comxa.com/index.html
: 帐号是 test@test.com 密码是 test
: 登入成功 会显示 you did it 登入失败 会跳js窗 说error
: 现在 想用python 3 练习登入
: 然而 每次都会传回登入错误的页面 不知道错在哪
: 实在是很困惑
: 不知是否有高手能救救我呢???? >< 谢谢各位
因为程式码本身就有错误了
重点在于 'action' 不是 web agent 能决定的参数
以本例来说,真正要填入的只有 'userName' 和 'pswd' 两个 input 字段
另外,也不需要再另外写一个 c.get
送出 request 后,得到的就已经是 response 了
这一部分,可以看一些 HTTP 协定的书或网站,会比较容易了解
例如:http://www.tutorialspoint.com/http/
附上范例,我自己试可成功,请自行参考
import requests
res = requests.post('http://pure.comxa.com/loginSuccessDisplay.php',
data={'userName': 'test@test.com', 'pswd': 'test'})
print res.text.encode('ascii', 'ignore')
: 程式码如下
: import requests
: import urllib
: from requests import session
: headers = {'User-Agent': 'Mozilla/5.0'}
: payload = {
: 'action': 'loginSuccessDisplay.php',
: 'userName':'test@test.com',
: 'pswd':'test'
: }
: with session() as c:
: c.post('http://pure.comxa.com/index.html',headers=headers,data=payload)
: response = c.get('http://pure.comxa.com/loginSuccessDisplay.php')
: # 改成index.html还是不行 会返回登入页面@@
: print(response.headers)
: print(response.text)
: 话说我的网页后台并不会产生session
: 而是只是单纯的验证username pswd有没有match
: 请问这是问题症结点吗?
: 还是我的 request 写错了呢? >< 恳请大大赐教谢谢
作者: phpjson (json_encode)   2016-04-14 00:59:00
非常谢谢您看到有些人会加action: ~ 或token: ~ 还以为要加XDrz

Links booklink

Contact Us: admin [ a t ] ucptt.com