虽然200
获得了400
,但我期待import requests
import json
import lxml.html
from lxml.cssselect import CSSSelector
from lxml.etree import fromstring
SELECTOR = CSSSelector('[type=hidden]')
BASE_URL = 'https://www.bonuscard.ch/myos/en/login'
LOGIN_URL = BASE_URL+'1.IFormSubmitListener-homePanel-loginPanel-loginForm'
# headers copied from chromium (returns 200)
headers = {
"Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding" : "gzip, deflate, br",
"Accept-Language" : "en,de;q=0.9",
"Cache-Control" : "no-cache",
"Connection" : "keep-alive",
"Content-Length" : "151",
"Content-Type" : "application/x-www-form-urlencoded",
"DNT" : "1",
"Host" : "www.bonuscard.ch",
"Origin" : "https: //www.bonuscard.ch",
"Pragma" : "no-cache",
"Referer" : "https: //www.bonuscard.ch/myos/en/login",
"Upgrade-Insecure-Requests" : "1",
"User-Agent" : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
}
with requests.Session() as session:
response = session.get(BASE_URL)
tree = lxml.html.fromstring(response.content)
keyOnly_token = [e.get('id') for e in SELECTOR(tree)][0]
payload = {
keyOnly_token:"",
"userName-border:userName-border_body:userName ": "jon@doe.com",
"password-border:password-border_body:password ": "123",
"login ": ""
}
response = session.post(LOGIN_URL,headers=headers,data=payload)
# Returns 400
print(response)
。
在我的请求中,有人看到我做错了吗?
代码:
headers
这些变化也没有显示出任何区别:
json=payload
data=payload
代替{{1}}