打開(kāi)攜程網(wǎng),查詢(xún)機(jī)票,如廣州到成都。
成都創(chuàng)新互聯(lián)是少有的做網(wǎng)站、成都網(wǎng)站制作、營(yíng)銷(xiāo)型企業(yè)網(wǎng)站、微信小程序、手機(jī)APP,開(kāi)發(fā)、制作、設(shè)計(jì)、買(mǎi)鏈接、推廣優(yōu)化一站式服務(wù)網(wǎng)絡(luò)公司,從2013年開(kāi)始,堅(jiān)持透明化,價(jià)格低,無(wú)套路經(jīng)營(yíng)理念。讓網(wǎng)頁(yè)驚喜每一位訪客多年來(lái)深受用戶(hù)好評(píng)這時(shí)網(wǎng)址為:http://flights.ctrip.com/booking/CAN-CTU-day-1.html?DDate1=2018-06-15
其中,CAN 表示廣州,CTU 表示成都,日期 “2018-06-15”就比較明顯了。一般的爬蟲(chóng),只有替換這幾個(gè)值,就可以遍歷了。但觀察發(fā)現(xiàn),有個(gè)鏈接可以看到當(dāng)前網(wǎng)頁(yè)的所有json格式的數(shù)據(jù)。如下
http://flights.ctrip.com/domesticsearch/search/SearchFirstRouteFlights?DCity1=CAN&ACity1=CTU&SearchType=S&DDate1=2018-06-15(后面省略……)
同樣可以看到城市和日期,該連接打開(kāi)的是 json 文件,里面存儲(chǔ)的就是當(dāng)前頁(yè)面的數(shù)據(jù)。顯示如下,其中 "fis" 則是航班信息。
每一次爬取只要替換城市代碼和日期即可,城市代碼自己手動(dòng)整理了一份:
city={"YIE":"阿爾山","AKU":"阿克蘇","RHT":"阿拉善右旗","AXF":"阿拉善左旗","AAT":"阿勒泰","NGQ":"阿里","MFM":"澳門(mén)" ,"AQG":"安慶","AVA":"安順","AOG":"鞍山","RLK":"巴彥淖爾","AEB":"百色","BAV":"包頭","BSD":"保山","BHY":"北海","BJS":"北京" ,"DBC":"白城","NBS":"白山","BFJ":"畢節(jié)","BPL":"博樂(lè)","CKG":"重慶","BPX":"昌都","CGD":"常德","CZX":"常州" ,"CHG":"朝陽(yáng)","CTU":"成都","JUH":"池州","CIF":"赤峰","SWA":"潮州","CGQ":"長(zhǎng)春","CSX":"長(zhǎng)沙","CIH":"長(zhǎng)治","CDE":"承德" ,"CWJ":"滄源","DAX":"達(dá)州","DLU":"大理","DLC":"大連","DQA":"大慶","DAT":"大同","DDG":"丹東","DCY":"稻城","DOY":"東營(yíng)" ,"DNH":"敦煌","DAX":"達(dá)縣","LUM":"德宏","EJN":"額濟(jì)納旗","DSN":"鄂爾多斯","ENH":"恩施","ERL":"二連浩特","FUO":"佛山" ,"FOC":"福州","FYJ":"撫遠(yuǎn)","FUG":"阜陽(yáng)","KOW":"贛州","GOQ":"格爾木","GYU":"固原","GYS":"廣元","CAN":"廣州","KWE":"貴陽(yáng)" ,"KWL":"桂林","HRB":"哈爾濱","HMI":"哈密","HAK":"???,"HLD":"海拉爾","HDG":"邯鄲","HZG":"漢中","HGH":"杭州","HFE":"合肥" ,"HTN":"和田","HEK":"黑河","HET":"呼和浩特","HIA":"淮安","HJJ":"懷化","TXN":"黃山","HUZ":"惠州","JXA":"雞西","TNA":"濟(jì)南" ,"JNG":"濟(jì)寧","JGD":"加格達(dá)奇","JMU":"佳木斯","JGN":"嘉峪關(guān)","SWA":"揭陽(yáng)","JIC":"金昌","KNH":"金門(mén)","JNZ":"錦州" ,"CYI":"嘉義","JHG":"景洪","JSJ":"建三江","JJN":"晉江","JGS":"井岡山","JDZ":"景德鎮(zhèn)","JIU":"九江","JZH":"九寨溝","KHG":"喀什" ,"KJH":"凱里","KGT":"康定","KRY":"克拉瑪依","KCA":"庫(kù)車(chē)","KRL":"庫(kù)爾勒","KMG":"昆明","LXA":"拉薩","LHW":"蘭州","HZH":"黎平" ,"LJG":"麗江","LLB":"荔波","LYG":"連云港","LPF":"六盤(pán)水","LFQ":"臨汾","LZY":"林芝","LNJ":"臨滄","LYI":"臨沂","LZH":"柳州" ,"LZO":"瀘州","LYA":"洛陽(yáng)","LLV":"呂梁","JMJ":"瀾滄","LCX":"龍巖","NZH":"滿(mǎn)洲里","LUM":"芒市","MXZ":"梅州","MIG":"綿陽(yáng)" ,"OHE":"漠河","MDG":"牡丹江","MFK":"馬祖" ,"KHN":"南昌","NAO":"南充","NKG":"南京","NNG":"南寧","NTG":"南通","NNY":"南陽(yáng)" ,"NGB":"寧波","NLH":"寧蒗","PZI":"攀枝花","SYM":"普洱","NDG":"齊齊哈爾","JIQ":"黔江","IQM":"且末","BPE":"秦皇島","TAO":"青島" ,"IQN":"慶陽(yáng)","JUZ":"衢州","RKZ":"日喀則","RIZ":"日照","SYX":"三亞","XMN":"廈門(mén)","SHA":"上海","SZX":"深圳","HPG":"神農(nóng)架" ,"SHE":"沈陽(yáng)","SJW":"石家莊","TCG":"塔城","HYN":"臺(tái)州","TYN":"太原","YTY":"泰州","TVS":"唐山","TCZ":"騰沖","TSN":"天津" ,"THQ":"天水","TGO":"通遼","TEN":"銅仁","TLQ":"吐魯番","WXN":"萬(wàn)州","WEH":"威海","WEF":"濰坊","WNZ":"溫州","WNH":"文山" ,"WUA":"烏海","HLH":"烏蘭浩特","URC":"烏魯木齊","WUX":"無(wú)錫","WUZ":"梧州","WUH":"武漢","WUS":"武夷山","SIA":"西安","XIC":"西昌" ,"XNN":"西寧","JHG":"西雙版納","XIL":"錫林浩特","DIG":"香格里拉(迪慶)","XFN":"襄陽(yáng)","ACX":"興義","XUZ":"徐州","HKG":"香港" ,"YNT":"煙臺(tái)","ENY":"延安","YNJ":"延吉","YNZ":"鹽城","YTY":"揚(yáng)州","LDS":"伊春","YIN":"伊寧","YBP":"宜賓","YIH":"宜昌" ,"YIC":"宜春","YIW":"義烏","INC":"銀川","LLF":"永州","UYN":"榆林","YUS":"玉樹(shù)","YCU":"運(yùn)城","ZHA":"湛江","DYG":"張家界" ,"ZQZ":"張家口","YZY":"張掖","ZAT":"昭通","CGO":"鄭州","ZHY":"中衛(wèi)","HSN":"舟山","ZUH":"珠海","WMT":"遵義(茅臺(tái))","ZYI":"遵義(新舟)"}
本文標(biāo)題:Python爬取攜程所有機(jī)票的實(shí)例代碼-創(chuàng)新互聯(lián)
轉(zhuǎn)載注明:http://muchs.cn/article32/idjpc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、微信小程序、企業(yè)網(wǎng)站制作、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容