syntax error, expect {, actual error, pos 0
期望是{,实际上是error
抓取目标:站点成功登录的Cookie
站点环境
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
接收数据类型为json类型,传参类型为urlcoded编码格式为UTF-8
content-type的取值是告诉服务端,要传递过去的内容类型。
当action为get时候,浏览器用x-www-form-urlencoded的编码方式把form数据转换成一个字串(name1=value1&name2=value2...),然后把这个字串append到url后面,用?分割,加载这个新的url。 当action为post时候,浏览器把form数据封装到http body中,然后发送到server。
检查站点 Formdata 数据类型如下
json: {"account_no":"xxx","account_pw":"***","token_code":"验证码"}
报错代码:
data = {'json':{"account_no": "xxx", "account_pw": "***", "token_code": f"{res}"}}
texts = requests.post(
url="http://www.xxx.com/login",
data=data,
headers=header
)
cookie={}
for i in texts.cookies:
cookie[i.name] = i.value
print(cookie)
提交表单后返回的页面信息
{"msg":[{"msg":"syntax error, expect {, actual error, pos 0"}],"msgType":"error"}
对此,尝试转换Formdata数据类型、尝试转换编码格式。