Home > other >  About python using json format requests by post request
About python using json format requests by post request

Time:09-22

Original intent for foreign friends to climb a few airlines ticket website, found that China Eastern website climbed the ticket, send a POST request with JSON format interfaces, the return code is 200, but is no results, return all empty, found the reason for sending the data of the room is the JSON format, but through fiddler caught access to send data in addition to the JSON data, the front must have searchCond=, concrete as shown, this how to structure a POST request in python, please?
Fiddler caught normal web search results:
 POST http://www.ceair.com/otabooking/flight-search! DoFlightSearch. HTTP/1.1 SHTML 
The user-agent: Mozilla/5.0 (Windows NT 10.0; Win64. X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36
The Accept - Encoding: gzip, deflate
Accept: application/json, text/javascript, */*; Q=0.01
Connection: keep alive -
Host: www.ceair.com
The content-type: application/x - WWW - form - urlencoded; Charset=utf-8
Origin: http://www.ceair.com
The Referer: http://www.ceair.com/booking/lhr-sha-200516_CNY.html
The Accept - Language: useful - CN, useful; Q=0.9, en. Q=0.8
Cookie: Webtrends=c1bd9729. 59 ec19eba8140; Language=zh_CN; _ga=GA1.2.1708422418.1581929338; EcrmWebtrends=81.104.156.52.1581929344111; Gr_user_id e1e0b4=11-806 - e - 4651-9 ac7-6 ba44b26476c; E60 grwng_uid=5 b76ecb2 - ec4b - 4-897 - a - d9c7fc409588; User_cookie=true; 84 bb15efa4e13721_gr_last_sent_cs1=5 b5d19979c3d373a30d1afd14ee1f813; apdid_data=https://bbs.csdn.net/topics/%7B%22time%22%3A1585492296549%2C%22token%22%3A%22APDIDJS_donghang_54acf34e6ad5998610a489ab26d24560%22%7D; _gid=GA1.2.222270777.1586091633; JSESSIONID=ZanxhlMTW5L7mSKqCyszXtfR. LaputaServer7; 84 bb15efa4e13721_gr_cs1=5 b5d19979c3d373a30d1afd14ee1f813
The Content - Length: 390

SearchCond={" adtCount ": 1," chdCount ": 0," infCount ": 0," currency ":" CNY ", "tripType" : "OW" and "how" : false, "reselect" : ""," page ":" 0 "and" sortType ":" a ", "sortExec" : "a", "segmentList" : [{" deptCd ":" LHR ", "arrCd" : "SHA", "deptDt" : "2020-05-16", "deptAirport" : ""," arrAirport ":" ", "deptCdTxt" : "LONDON", "arrCdTxt" : "SHANGHAI", "deptCityCode" : "LON", "arrCityCode" : "SHA"}], "version" : "1.0" a.}


Using the python of mounting a post request with json format caught results:
 POST http://www.ceair.com/otabooking/flight-search! DoFlightSearch. HTTP/1.1 SHTML 
The user-agent: Mozilla/5.0 (Windows NT 10.0; Win64. X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36
The Accept - Encoding: gzip, deflate
Accept: application/json, text/javascript, */*; Q=0.01
Connection: keep alive -
Host: www.ceair.com
The content-type: application/x - WWW - form - urlencoded; Charset=utf-8
Origin: http://www.ceair.com
The Referer: http://www.ceair.com/booking/lhr-sha-200516_CNY.html
The Accept - Language: useful - CN, useful; Q=0.9, en. Q=0.8
Cookie: Webtrends=c1bd9729. 59 ec19eba8140; Language=zh_CN; _ga=GA1.2.1708422418.1581929338; EcrmWebtrends=81.104.156.52.1581929344111; Gr_user_id e1e0b4=11-806 - e - 4651-9 ac7-6 ba44b26476c; E60 grwng_uid=5 b76ecb2 - ec4b - 4-897 - a - d9c7fc409588; User_cookie=true; 84 bb15efa4e13721_gr_last_sent_cs1=5 b5d19979c3d373a30d1afd14ee1f813; apdid_data=https://bbs.csdn.net/topics/%7B%22time%22%3A1585492296549%2C%22token%22%3A%22APDIDJS_donghang_54acf34e6ad5998610a489ab26d24560%22%7D; _gid=GA1.2.222270777.1586091633; JSESSIONID=ZanxhlMTW5L7mSKqCyszXtfR. LaputaServer7; 84 bb15efa4e13721_gr_cs1=5 b5d19979c3d373a30d1afd14ee1f813
The Content - Length: 390

{" adtCount ": 1," chdCount ": 0," infCount ": 0," currency ":" CNY ", "tripType" : "OW" and "how" : false, "reselect" : ""," page ":" 0 "and" sortType ":" a ", "sortExec" : "a", "segmentList" : [{" deptCd ":" LHR ", "arrCd" : "SHA", "deptDt" : "2020-05-16", "deptAirport" : ""," arrAirport ":" ", "deptCdTxt" : "LONDON", "arrCdTxt" : "SHANGHAI", "deptCityCode" : "LON", "arrCityCode" : "SHA"}], "version" : "1.0" a.}


My python code:
 
The import requests
The import json
Requests. Packages. Urllib3. Disable_warnings ()
Url="http://www.ceair.com/otabooking/flight-search! DoFlightSearch. SHTML "
Headers={
"The Host" : "www.ceair.com",
"The Proxy - Connection" : "keep - the alive,"
"Accept: application/json, text/javascript, */*;
q=0.01,"X - Requested - With" : "the XMLHttpRequest,"
"The user-agent: Mozilla/5.0 (Windows NT 10.0; Win64. X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 ",
The content-type: "application/x - WWW - form - urlencoded; Charset=utf-8,
""Origin" : "http://www.ceair.com",
"Referer" : "http://www.ceair.com/booking/lhr-sha-200516_CNY.html",
"Accept - the Encoding", "gzip, deflate",
"Accept - Language" : "useful - CN, useful; Q=0.9, en.
q=0.8,"Cookie", "Webtrends=c1bd9729. 59 ec19eba8140; Language=zh_CN; _ga=GA1.2.1708422418.1581929338; EcrmWebtrends=81.104.156.52.1581929344111; Gr_user_id e1e0b4=11-806 - e - 4651-9 ac7-6 ba44b26476c; E60 grwng_uid=5 b76ecb2 - ec4b - 4-897 - a - d9c7fc409588; User_cookie=true; 84 bb15efa4e13721_gr_last_sent_cs1=5 b5d19979c3d373a30d1afd14ee1f813; apdid_data=https://bbs.csdn.net/topics/%7B%22time%22%3A1585492296549%2C%22token%22%3A%22APDIDJS_donghang_54acf34e6ad5998610a489ab26d24560%22%7D; _gid=GA1.2.222270777.1586091633; JSESSIONID=ZanxhlMTW5L7mSKqCyszXtfR. LaputaServer7; 84 bb15efa4e13721_gr_cs1=5 b5d19979c3d373a30d1afd14ee1f813
"}

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related