如何获取以下请求的随机请求ID

时间:2015-10-30 16:39:15

标签: python web-crawler python-requests

我怎样才能获得随机请求ID

我试图通过抓取https://www.flyvair.com/en来获取故障单数据。

此curl请求将获取我想要的数据

curl 'https://api.flyvair.com/api/v1/bookings/flightavailability?origin=TPE&dstn=CNX&adult=1&child=0&infant=0&promoCode=&departFrom=2015-10-27&departTo=2015-11-04&returnFrom=2015-10-27&returnTo=2015-11-04' -X OPTIONS -H 'Access-Control-Request-Method: GET' -H 'Origin: https://www.flyvair.com' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36' -H 'Accept: */*' -H 'Referer: https://www.flyvair.com/en/book.html' -H 'Connection: keep-alive' -H 'AlexaToolbar-ALX_NS_PH: AlexaToolbar/alxg-3.3' -H 'Access-Control-Request-Headers: accept, x-connect-id' --compressed

但是我发现此请求有一个关键令牌x-connect-id

似乎x-connect-id

请求OPTIONS request

如何将此操作转换为Pyhton请求

我尝试使用req_a执行相同操作,并按req_b获取数据,

然而,它根本没有用。

我当前的代码

pre_headers = {
    'Access-Control-Request-Method': 'GET',
    'Origin': 'https://www.flyvair.com',
    'Accept-Encoding': 'gzip, deflate, sdch',
    'Accept-Language': 'en-US,en;q=0.8',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36',
    'Accept': '*/*',
    'Referer': 'https://www.flyvair.com/en/book.html',
    'Connection': 'keep-alive',
    'Access-Control-Request-Headers': 'accept, x-connect-id',
}



params = {
  "origin": "TPE",
  "dstn": "CNX",
  "adult": "1",
  "child": "0",
  "infant": "0",
  "promoCode": None,
  "departFrom": "2015-10-27",
  "departTo": "2015-11-04",
  "returnFrom": "2015-10-27",
  "returnTo": "2015-11-04"
}

req = requests.session()
req.get('https://www.flyvair.com/en/')
req_a = req.get('https://api.flyvair.com/api/v1/bookings/flightavailability?'+urllib.parse.urlencode(params), headers=pre_headers)
print(req.headers)
req_b = req.get('https://api.flyvair.com/api/v1/bookings/flightavailability?'+urllib.parse.urlencode(params), headers=req.headers)
# resp = req.get('https://api.flyvair.com/api/v1/bookings/flightavailability', data=json.dumps(params))

1 个答案:

答案 0 :(得分:0)

您必须在请求标头中包含x-connect-id。它可以通过此POST https://security.flyvair.com/api/v1/users/tokens

获取