【发布时间】:2012-05-30 16:23:26
【问题描述】:
我有通过发布请求进行身份验证的简单代码。 服务器每个请求都会生成“javax.faces.ViewState”变量 比如 javax.faces.ViewState=123456784356754
import requests
import re
global_headers = { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/12.0',
'Accept': 'application/xml, text/xml, */*; q=0.01',
'Referer': 'http://serrver.com/login/'}
req = requests.Session(headers=global_headers)
def javalue_parser():
javalue = re.findall(r'name="javax.faces.ViewState" id="javax.faces.ViewState" value="(.*?)"')
print javalue[0]
return javalue
my_post_req = req.post('http://server.com/login/',
data={'phone': '+11(123)456-78-91',
'loginForm': 'loginForm',
'javax.faces.ViewState': "%s" % javalue_parser()
})
我总是出错
Traceback (most recent call last):
File "rework_sms.py", line 28, in <module>
'javax.faces.ViewState': "%s" % javalue_parser()
File "test.py", line 19, in javalue_parser
javalue = re.findall(r'name="javax.faces.ViewState" id="javax.faces.ViewState" value="(.*?)"')
TypeError: findall() takes at least 2 arguments (1 given)
需要什么论据?
【问题讨论】:
-
什么你想用正则表达式from找到?这是另一个论点。
-
一些数字如 12344556,但我无法在 post 请求中执行函数如果我使用 javalue_parser(my_post_req.content) 它工作正常
标签: python post get python-requests