|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import requests
url = "https://kyfw.12306.cn/otn/czxx/queryByTrainNo?train_no=5u0000G48803&from_station_telecode=NXG&to_station_telecode=BXP&depart_date=2020-03-31"
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Content-Type": "application/json;charset=UTF-8",
"Transfer-Encoding": "chunked",
"X-Cdn-Src-Port": "1102",
"X-Via": "1.1 changzhoudianxin63:1 (Cdn Cache Server V2.0)",
"X-Ws-Request-Id": "5e849878_changzhoudianxi_3647-17242",
"Connection": "keep-alive",
"Cookie": "JSESSIONID=98AAAFB104606B95E832E97CD7897063; RAIL_DEVICEID=W0hqKPPHPVNa2Yxz5wGDGHupp1TnExRfzSpcbzd7kYY7VUYwe301xEbw-CcwgXEyOaDJ4dvi_Fggow2sd0mDYqN3Wsbr4Bq2E-Bf--Wk3A7GHTUPojpT0g2EfWZAKfN5xjzZI1-m343uIMAOfKme4NHFmi5UxT6x; RAIL_EXPIRATION=1585664545878; _jc_save_toDate=2020-03-28; _jc_save_wfdc_flag=dc; _jc_save_toStation=%u5317%u4EAC%2CBJP; _jc_save_fromStation=%u6B66%u6C49%2CWHN; _jc_save_fromDate=2020-04-06; route=495c805987d0f5c8c84b14f60212447d; BIGipServerotn=351273482.50210.0000",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"
}
res = requests.get(url,headers=headers)
print (res)
在浏览器输入url,可以获取具体数据,但是用上述代码只是返回<Response [200]>,请问问题出在哪儿了?
想打印网站内容可以使用下面的代码:
import requests
url = "https://kyfw.12306.cn/otn/czxx/queryByTrainNo?train_no=5u0000G48803&from_station_telecode=NXG&to_station_telecode=BXP&depart_date=2020-03-31"
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Content-Type": "application/json;charset=UTF-8",
"Transfer-Encoding": "chunked",
"X-Cdn-Src-Port": "1102",
"X-Via": "1.1 changzhoudianxin63:1 (Cdn Cache Server V2.0)",
"X-Ws-Request-Id": "5e849878_changzhoudianxi_3647-17242",
"Connection": "keep-alive",
"Cookie": "JSESSIONID=98AAAFB104606B95E832E97CD7897063; RAIL_DEVICEID=W0hqKPPHPVNa2Yxz5wGDGHupp"
"1TnExRfzSpcbzd7kYY7VUYwe301xEbw-CcwgXEyOaDJ4dvi_Fggow2sd0mDYqN3Wsbr4Bq2E-Bf--Wk3A7GHTU"
"PojpT0g2EfWZAKfN5xjzZI1-m343uIMAOfKme4NHFmi5UxT6x; RAIL_EXPIRATION=1585664545878; _jc_s"
"ave_toDate=2020-03-28; _jc_save_wfdc_flag=dc; _jc_save_toStation=%u5317%u4EAC%2CBJP; "
"_jc_save_fromStation=%u6B66%u6C49%2CWHN; _jc_save_fromDate=2020-04-06; route=495c805987"
"d0f5c8c84b14f60212447d; BIGipServerotn=351273482.50210.0000",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chr"
"ome/80.0.3987.149 Safari/537.36"
}
res = requests.get(url, headers=headers)
print(res.text)
|
|