第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

攜程網(wǎng)機(jī)票查詢腳本,無(wú)法正常運(yùn)行,麻煩大家看看錯(cuò)在哪里.....

攜程網(wǎng)機(jī)票查詢腳本,無(wú)法正常運(yùn)行,麻煩大家看看錯(cuò)在哪里.....

慕勒13948 2018-10-04 08:23:05
在知乎上看到了一個(gè)關(guān)于攜程網(wǎng)機(jī)票查詢的爬蟲程序 :https://zhuanlan.zhihu.com/p/33148780?嘗試著在本機(jī)運(yùn)行時(shí)候,發(fā)現(xiàn)在運(yùn)行airline_ticket.py文件的時(shí)候出現(xiàn)報(bào)錯(cuò):【代碼腳本】如下:import requests,json,osfrom docopt import docoptfrom prettytable import PrettyTablefrom colorama import init,Forefrom air_stations import stationsfromCity = input('Please input the city you want leave :')toCity = input('Please input the city you will arrive :')tripDate = input('Please input the date(Example:2018-10-29) :')init()class TrainsCollection:? header = '航空公司 航班 機(jī)場(chǎng) 時(shí)間 機(jī)票價(jià)格 機(jī)場(chǎng)建設(shè)費(fèi)'.split()? def __init__(self,airline_tickets):? ? ?self.airline_tickets = airline_tickets@propertydef plains(self):? air_company = {"G5":"華夏航空","9C":"春秋航空","MU":"東方航空","NS":"河北航空","HU":"海南航空","HO":"吉祥航空","CZ":"南方航空","FM":"上海航空","ZH":"深圳航空","MF":"廈門航空","CA":"中國(guó)國(guó)航","KN":"中國(guó)聯(lián)航"}? for item in self.airline_tickets:? ? try:? ? ? strs = air_company[item['alc']]? ? except KeyError:? ? ? strs = item['alc']? ? airline_data = [? ? Fore.BLUE + strs + Fore.RESET,? ? Fore.BLUE + item['fn'] + Fore.RESET,? ? '\n'.join([Fore.YELLOW + item['dpbn'] + Fore.RESET,? ? Fore.CYAN + item['apbn'] + Fore.RESET]),? ?'\n'.join([Fore.YELLOW + item['dt'] + Fore.RESET,? ? Fore.CYAN + item['at'] + Fore.RESET]),? ? item['lp'],? ? item['tax'],? ? ]? ? yield airline_datadef pretty_print(self):? ?pt = PrettyTable()? ?pt._set_field_names(self.header)? ?for airline_data in self.plains:? ? pt.add_row(airline_data)? ?print(pt)def doit():? headers = {? ? "Cookie":"自定義",? ? "User-Agent": "自定義",? ?}? arguments = {? ?'from':fromCity,? ?'to':toCity,? ?'date':tripDate? ?}? DCity1 = stations[arguments['from']]? ACity1 = stations[arguments['to']]? DDate1 = arguments['date']? url=("http://flights.ctrip.com/domesticsearch/search/SearchFirstRouteFlights?DCity1={}&ACity1={}&SearchType=S&DDate1={}").format(DCity1,ACity1,DDate1)? try:? ? ?r = requests.get(url,headers = headers,verify=False)? except Exception as e:? ? ? print(repr(e))? ? ? print(url)? ? ? airline_tickets = r.json()['fis']? ? ? TrainsCollection(airline_tickets).pretty_print()if __name__ == '__main__':? doit()
查看完整描述

3 回答

?
鹹魚Yu

TA貢獻(xiàn)3條經(jīng)驗(yàn) 獲得超0個(gè)贊

r 放 try 外面定義試試

查看完整回答
反對(duì) 回復(fù) 2019-01-03
  • 3 回答
  • 0 關(guān)注
  • 1475 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)