[{"data":1,"prerenderedAt":5901},["ShallowReactive",2],{"post-2025-08-01-train-tickets":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"tags":11,"body":15,"_type":5895,"_id":5896,"_source":5897,"_file":5898,"_stem":5899,"_extension":5900},"\u002Fblog\u002F2025-08-01-train-tickets","blog",false,"","12306 车票查询接口实现","Python爬虫实战：使用PyQt5构建12306火车票查询GUI工具，包含窗体设计、请求参数分析与数据展示。","2025-08-01",[12,13,14],"Python","爬虫","PyQt5",{"type":16,"children":17,"toc":5881},"root",[18,27,31,37,46,55,61,64,69,101,113,118,121,126,134,141,146,151,159,173,181,186,194,199,345,350,586,594,599,908,916,925,930,938,946,983,991,999,1004,1017,1187,1192,1212,1278,1328,1446,1451,1562,1570,1590,1735,1748,1875,1888,1951,1959,1967,2096,2108,2131,2136,2144,2149,2152,2157,2186,2199,2204,2212,2220,2225,2233,2238,2246,2251,2254,2259,2280,2288,2296,2301,2309,2325,2338,2382,2485,2493,2497,2526,2643,2663,2733,2745,2753,2758,2761,2767,2772,2777,2785,2798,2806,2829,2837,2873,2980,3001,3052,3427,3432,3534,3565,3595,3600,4515,4521,4526,4568,4607,4626,4777,4782,4916,4978,5088,5101,5258,5279,5397,5417,5755,5767,5862,5867,5875],{"type":19,"tag":20,"props":21,"children":23},"element","h2",{"id":22},"_12306爬票概述",[24],{"type":25,"value":26},"text","12306爬票概述",{"type":19,"tag":28,"props":29,"children":30},"hr",{},[],{"type":19,"tag":32,"props":33,"children":34},"p",{},[35],{"type":25,"value":36},"无论是出差还是旅行，都无法离开交通工具的支持。现如今随着科技水平的提高，高铁与动车成为人们喜爱的交通工具。如果想要知道每列车次的时间信息，都需要在各类的列车网站中进行查询，本项目将通过Python的爬虫技术实现一个12306爬票工具，如图所示。",{"type":19,"tag":38,"props":39,"children":43},"video",{"src":40,"controls":41,"style":42},"\u002Fimages\u002Fblog\u002Ftrain-tickets\u002F12306-assistant.mp4",true,"max-width:100%;display:block;margin:1.5em auto;border-radius:4px",[44],{"type":25,"value":45},"\n  您的浏览器不支持视频播放\n",{"type":19,"tag":32,"props":47,"children":48},{},[49],{"type":19,"tag":50,"props":51,"children":54},"img",{"alt":52,"src":53},"Pasted image 20250801224932","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250801224932.png",[],{"type":19,"tag":20,"props":56,"children":58},{"id":57},"搭建qt环境",[59],{"type":25,"value":60},"搭建QT环境",{"type":19,"tag":28,"props":62,"children":63},{},[],{"type":19,"tag":32,"props":65,"children":66},{},[67],{"type":25,"value":68},"Qt是Python开发窗体的工具之一，它不仅与Python有着良好的兼容性，还可以通过可视化拖拽的方式进行窗体的创建，提高开发人员的开发效率，因此受到开发人员的喜爱。",{"type":19,"tag":32,"props":70,"children":71},{},[72,78,80,85,87,92,94,99],{"type":19,"tag":73,"props":74,"children":75},"strong",{},[76],{"type":25,"value":77},"第一步",{"type":25,"value":79},"：安装Python解释器\n",{"type":19,"tag":73,"props":81,"children":82},{},[83],{"type":25,"value":84},"第二步",{"type":25,"value":86},"：安装Pycharm编辑器\n",{"type":19,"tag":73,"props":88,"children":89},{},[90],{"type":25,"value":91},"第三步",{"type":25,"value":93},"：在Python上安装Qt模块环境\n",{"type":19,"tag":73,"props":95,"children":96},{},[97],{"type":25,"value":98},"第四步",{"type":25,"value":100},"：结合安装的PyQt5模块进行Pycharm的配置",{"type":19,"tag":32,"props":102,"children":103},{},[104,106],{"type":25,"value":105},"详细QT环境的配置，请访问 ",{"type":19,"tag":107,"props":108,"children":110},"a",{"href":109},"\u002Fblog\u002F2025-07-16-pyqt5-pyqt5",[111],{"type":25,"value":112},"PyQt5环境搭建",{"type":19,"tag":20,"props":114,"children":116},{"id":115},"主窗体设计",[117],{"type":25,"value":115},{"type":19,"tag":28,"props":119,"children":120},{},[],{"type":19,"tag":32,"props":122,"children":123},{},[124],{"type":25,"value":125},"Python、QT与PyCharm配置完成后，接下来需要对快手爬票的主窗体进行设计，首先需要创建主窗体外层，然后依次添加顶部图片、查询区域、选择车次类型区域、分类图片区域、信息表格区域。设计顺序如图所示。",{"type":19,"tag":32,"props":127,"children":128},{},[129],{"type":19,"tag":50,"props":130,"children":133},{"alt":131,"src":132},"Pasted image 20250731211018","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731211018.png",[],{"type":19,"tag":135,"props":136,"children":138},"h3",{"id":137},"qt拖曳控件",[139],{"type":25,"value":140},"Qt拖曳控件",{"type":19,"tag":32,"props":142,"children":143},{},[144],{"type":25,"value":145},"了解了窗体设计思路以后，接下来需要实现快手爬票的窗体。由于在14.4.2小节中已经将Python、QT与PyCharm三个开发工具进行了环境配置，所以创建窗体时只需要启动PyCharm开发工具即可，实现窗体的具体步骤如下：",{"type":19,"tag":32,"props":147,"children":148},{},[149],{"type":25,"value":150},"1）在PyCharm开发工具中创建新的Python项目，项目打开完成后，在顶部的菜单栏中依次单击Tools → External Tools → Qt Designer打开设计师，如图所示：",{"type":19,"tag":32,"props":152,"children":153},{},[154],{"type":19,"tag":50,"props":155,"children":158},{"alt":156,"src":157},"Pasted image 20250731161043","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731161043.png",[],{"type":19,"tag":32,"props":160,"children":161},{},[162,164,171],{"type":25,"value":163},"2）单击Qt Designer快捷工具后，Qt的窗口编辑工具将自动打开，并且会自动弹出一个新建窗体的窗口，在该窗口中选择一个主窗体的模板，这里选择",{"type":19,"tag":165,"props":166,"children":168},"code",{"className":167},[],[169],{"type":25,"value":170},"Main Window",{"type":25,"value":172},"然后单击创建按钮即可，如图所示：",{"type":19,"tag":32,"props":174,"children":175},{},[176],{"type":19,"tag":50,"props":177,"children":180},{"alt":178,"src":179},"Pasted image 20250731161313","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731161313.png",[],{"type":19,"tag":32,"props":182,"children":183},{},[184],{"type":25,"value":185},"3）主窗体创建完成后，自动进入到Qt Designer的设计界面，顶部区域是菜单栏与快捷菜单选项，左侧区域是各种控件与布局，中间的区域为编辑区域，该区域可以将控件拖曳至此处，也可以预览窗体的设计效果。右侧上方是对象查看器，此处列出所有控件以及彼此所属的关系层。右侧中间的位置是属性编辑器，此处可以设置控件的各种属性。右侧底部的位置分别为信号\u002F槽编辑器、动作编辑器及资源浏览器，具体位置如图所示：",{"type":19,"tag":32,"props":187,"children":188},{},[189],{"type":19,"tag":50,"props":190,"children":193},{"alt":191,"src":192},"Pasted image 20250731162052","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731162052.png",[],{"type":19,"tag":32,"props":195,"children":196},{},[197],{"type":25,"value":198},"4）根据设计思路依次将指定的控件拖拽至主窗体中，首先添加主窗体容器内的控件如下表所示。",{"type":19,"tag":200,"props":201,"children":202},"table",{},[203,237],{"type":19,"tag":204,"props":205,"children":206},"thead",{},[207],{"type":19,"tag":208,"props":209,"children":210},"tr",{},[211,221,229],{"type":19,"tag":212,"props":213,"children":215},"th",{"align":214},"center",[216],{"type":19,"tag":73,"props":217,"children":218},{},[219],{"type":25,"value":220},"对 象 名 称",{"type":19,"tag":212,"props":222,"children":223},{"align":214},[224],{"type":19,"tag":73,"props":225,"children":226},{},[227],{"type":25,"value":228},"控 件 名 称",{"type":19,"tag":212,"props":230,"children":231},{"align":214},[232],{"type":19,"tag":73,"props":233,"children":234},{},[235],{"type":25,"value":236},"描    述",{"type":19,"tag":238,"props":239,"children":240},"tbody",{},[241,268,294,319],{"type":19,"tag":208,"props":242,"children":243},{},[244,254,263],{"type":19,"tag":245,"props":246,"children":247},"td",{"align":214},[248],{"type":19,"tag":165,"props":249,"children":251},{"className":250},[],[252],{"type":25,"value":253},"centralwidget",{"type":19,"tag":245,"props":255,"children":256},{"align":214},[257],{"type":19,"tag":165,"props":258,"children":260},{"className":259},[],[261],{"type":25,"value":262},"QWidget",{"type":19,"tag":245,"props":264,"children":265},{"align":214},[266],{"type":25,"value":267},"该控件与对象名称是创建主窗体后默认生成，为主窗体外层容器",{"type":19,"tag":208,"props":269,"children":270},{},[271,280,289],{"type":19,"tag":245,"props":272,"children":273},{"align":214},[274],{"type":19,"tag":165,"props":275,"children":277},{"className":276},[],[278],{"type":25,"value":279},"label_title_img",{"type":19,"tag":245,"props":281,"children":282},{"align":214},[283],{"type":19,"tag":165,"props":284,"children":286},{"className":285},[],[287],{"type":25,"value":288},"QLabel",{"type":19,"tag":245,"props":290,"children":291},{"align":214},[292],{"type":25,"value":293},"该控件位于主窗体容器内，用于设置顶部图片、对象名称自定义",{"type":19,"tag":208,"props":295,"children":296},{},[297,306,314],{"type":19,"tag":245,"props":298,"children":299},{"align":214},[300],{"type":19,"tag":165,"props":301,"children":303},{"className":302},[],[304],{"type":25,"value":305},"label_train_img",{"type":19,"tag":245,"props":307,"children":308},{"align":214},[309],{"type":19,"tag":165,"props":310,"children":312},{"className":311},[],[313],{"type":25,"value":288},{"type":19,"tag":245,"props":315,"children":316},{"align":214},[317],{"type":25,"value":318},"该控件位于主窗体容器内，用于设置分类图片、对象名称自定义",{"type":19,"tag":208,"props":320,"children":321},{},[322,331,340],{"type":19,"tag":245,"props":323,"children":324},{"align":214},[325],{"type":19,"tag":165,"props":326,"children":328},{"className":327},[],[329],{"type":25,"value":330},"tableView",{"type":19,"tag":245,"props":332,"children":333},{"align":214},[334],{"type":19,"tag":165,"props":335,"children":337},{"className":336},[],[338],{"type":25,"value":339},"QTableView",{"type":19,"tag":245,"props":341,"children":342},{"align":214},[343],{"type":25,"value":344},"该控件位于主窗体容器内，用于显示信息表格、对象名称自定义",{"type":19,"tag":32,"props":346,"children":347},{},[348],{"type":25,"value":349},"向主窗体中添加查询区域容器与控件，如下表所示。",{"type":19,"tag":200,"props":351,"children":352},{},[353,381],{"type":19,"tag":204,"props":354,"children":355},{},[356],{"type":19,"tag":208,"props":357,"children":358},{},[359,366,373],{"type":19,"tag":212,"props":360,"children":361},{"align":214},[362],{"type":19,"tag":73,"props":363,"children":364},{},[365],{"type":25,"value":220},{"type":19,"tag":212,"props":367,"children":368},{"align":214},[369],{"type":19,"tag":73,"props":370,"children":371},{},[372],{"type":25,"value":228},{"type":19,"tag":212,"props":374,"children":375},{"align":214},[376],{"type":19,"tag":73,"props":377,"children":378},{},[379],{"type":25,"value":380},"描　　述",{"type":19,"tag":238,"props":382,"children":383},{},[384,409,434,459,484,510,536,561],{"type":19,"tag":208,"props":385,"children":386},{},[387,396,404],{"type":19,"tag":245,"props":388,"children":389},{"align":214},[390],{"type":19,"tag":165,"props":391,"children":393},{"className":392},[],[394],{"type":25,"value":395},"widget_query",{"type":19,"tag":245,"props":397,"children":398},{"align":214},[399],{"type":19,"tag":165,"props":400,"children":402},{"className":401},[],[403],{"type":25,"value":262},{"type":19,"tag":245,"props":405,"children":406},{"align":214},[407],{"type":25,"value":408},"该控件位于用于显示查询区域，对象名称自定义，该控件为查询区域的容器",{"type":19,"tag":208,"props":410,"children":411},{},[412,421,429],{"type":19,"tag":245,"props":413,"children":414},{"align":214},[415],{"type":19,"tag":165,"props":416,"children":418},{"className":417},[],[419],{"type":25,"value":420},"label",{"type":19,"tag":245,"props":422,"children":423},{"align":214},[424],{"type":19,"tag":165,"props":425,"children":427},{"className":426},[],[428],{"type":25,"value":288},{"type":19,"tag":245,"props":430,"children":431},{"align":214},[432],{"type":25,"value":433},"该控件位于查询区域的容器内，用于显示“出发地：”文字、对象名称自定义",{"type":19,"tag":208,"props":435,"children":436},{},[437,446,454],{"type":19,"tag":245,"props":438,"children":439},{"align":214},[440],{"type":19,"tag":165,"props":441,"children":443},{"className":442},[],[444],{"type":25,"value":445},"label_2",{"type":19,"tag":245,"props":447,"children":448},{"align":214},[449],{"type":19,"tag":165,"props":450,"children":452},{"className":451},[],[453],{"type":25,"value":288},{"type":19,"tag":245,"props":455,"children":456},{"align":214},[457],{"type":25,"value":458},"该控件位于查询区域的容器内，用于查询区域的容器内，显示“目的地：”文字、对象名称自定义",{"type":19,"tag":208,"props":460,"children":461},{},[462,471,479],{"type":19,"tag":245,"props":463,"children":464},{"align":214},[465],{"type":19,"tag":165,"props":466,"children":468},{"className":467},[],[469],{"type":25,"value":470},"label_3",{"type":19,"tag":245,"props":472,"children":473},{"align":214},[474],{"type":19,"tag":165,"props":475,"children":477},{"className":476},[],[478],{"type":25,"value":288},{"type":19,"tag":245,"props":480,"children":481},{"align":214},[482],{"type":25,"value":483},"该控件位于查询区域的容器内，用于显示“出发日：”文字、对象名称自定义",{"type":19,"tag":208,"props":485,"children":486},{},[487,496,505],{"type":19,"tag":245,"props":488,"children":489},{"align":214},[490],{"type":19,"tag":165,"props":491,"children":493},{"className":492},[],[494],{"type":25,"value":495},"pushButton",{"type":19,"tag":245,"props":497,"children":498},{"align":214},[499],{"type":19,"tag":165,"props":500,"children":502},{"className":501},[],[503],{"type":25,"value":504},"QPushButton",{"type":19,"tag":245,"props":506,"children":507},{"align":214},[508],{"type":25,"value":509},"该控件位于查询区域的容器内，用于显示查询按钮，对象名称自定义",{"type":19,"tag":208,"props":511,"children":512},{},[513,522,531],{"type":19,"tag":245,"props":514,"children":515},{"align":214},[516],{"type":19,"tag":165,"props":517,"children":519},{"className":518},[],[520],{"type":25,"value":521},"textEdit",{"type":19,"tag":245,"props":523,"children":524},{"align":214},[525],{"type":19,"tag":165,"props":526,"children":528},{"className":527},[],[529],{"type":25,"value":530},"QTextEdit",{"type":19,"tag":245,"props":532,"children":533},{"align":214},[534],{"type":25,"value":535},"该控件位于查询区域的容器内，用于显示“出发地”所对应的编辑框、对象名称自定义",{"type":19,"tag":208,"props":537,"children":538},{},[539,548,556],{"type":19,"tag":245,"props":540,"children":541},{"align":214},[542],{"type":19,"tag":165,"props":543,"children":545},{"className":544},[],[546],{"type":25,"value":547},"textEdit_2",{"type":19,"tag":245,"props":549,"children":550},{"align":214},[551],{"type":19,"tag":165,"props":552,"children":554},{"className":553},[],[555],{"type":25,"value":530},{"type":19,"tag":245,"props":557,"children":558},{"align":214},[559],{"type":25,"value":560},"该控件位于查询区域的容器内，用于显示“目的地”所对应的编辑框、对象名称自定义",{"type":19,"tag":208,"props":562,"children":563},{},[564,573,581],{"type":19,"tag":245,"props":565,"children":566},{"align":214},[567],{"type":19,"tag":165,"props":568,"children":570},{"className":569},[],[571],{"type":25,"value":572},"textEdit_3",{"type":19,"tag":245,"props":574,"children":575},{"align":214},[576],{"type":19,"tag":165,"props":577,"children":579},{"className":578},[],[580],{"type":25,"value":530},{"type":19,"tag":245,"props":582,"children":583},{"align":214},[584],{"type":25,"value":585},"该控件位于查询区域的容器内，用于显示“出发日”所对应的编辑框、对象名称自定义",{"type":19,"tag":32,"props":587,"children":588},{},[589],{"type":19,"tag":50,"props":590,"children":593},{"alt":591,"src":592},"Pasted image 20250731170433","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731170433.png",[],{"type":19,"tag":32,"props":595,"children":596},{},[597],{"type":25,"value":598},"向主窗体中添加选择车次类型容器与控件，如下表所示：",{"type":19,"tag":200,"props":600,"children":601},{},[602,629],{"type":19,"tag":204,"props":603,"children":604},{},[605],{"type":19,"tag":208,"props":606,"children":607},{},[608,615,622],{"type":19,"tag":212,"props":609,"children":610},{"align":214},[611],{"type":19,"tag":73,"props":612,"children":613},{},[614],{"type":25,"value":220},{"type":19,"tag":212,"props":616,"children":617},{"align":214},[618],{"type":19,"tag":73,"props":619,"children":620},{},[621],{"type":25,"value":228},{"type":19,"tag":212,"props":623,"children":624},{"align":214},[625],{"type":19,"tag":73,"props":626,"children":627},{},[628],{"type":25,"value":236},{"type":19,"tag":238,"props":630,"children":631},{},[632,657,683,708,733,758,783,808,833,858,883],{"type":19,"tag":208,"props":633,"children":634},{},[635,644,652],{"type":19,"tag":245,"props":636,"children":637},{"align":214},[638],{"type":19,"tag":165,"props":639,"children":641},{"className":640},[],[642],{"type":25,"value":643},"widget_checkBox",{"type":19,"tag":245,"props":645,"children":646},{"align":214},[647],{"type":19,"tag":165,"props":648,"children":650},{"className":649},[],[651],{"type":25,"value":262},{"type":19,"tag":245,"props":653,"children":654},{"align":214},[655],{"type":25,"value":656},"该控件用于显示选择车次类型区域、对象名称自定义，该控件为选择车次类型区域的容器",{"type":19,"tag":208,"props":658,"children":659},{},[660,669,678],{"type":19,"tag":245,"props":661,"children":662},{"align":214},[663],{"type":19,"tag":165,"props":664,"children":666},{"className":665},[],[667],{"type":25,"value":668},"checkBox_D",{"type":19,"tag":245,"props":670,"children":671},{"align":214},[672],{"type":19,"tag":165,"props":673,"children":675},{"className":674},[],[676],{"type":25,"value":677},"QCheckBox",{"type":19,"tag":245,"props":679,"children":680},{"align":214},[681],{"type":25,"value":682},"该控件位于选择车次类型的容器内，用于选择动车类型、对象名称自定义",{"type":19,"tag":208,"props":684,"children":685},{},[686,695,703],{"type":19,"tag":245,"props":687,"children":688},{"align":214},[689],{"type":19,"tag":165,"props":690,"children":692},{"className":691},[],[693],{"type":25,"value":694},"checkBox_G",{"type":19,"tag":245,"props":696,"children":697},{"align":214},[698],{"type":19,"tag":165,"props":699,"children":701},{"className":700},[],[702],{"type":25,"value":677},{"type":19,"tag":245,"props":704,"children":705},{"align":214},[706],{"type":25,"value":707},"该控件位于选择车次类型的容器内，用于选择高铁类型、对象名称自定义",{"type":19,"tag":208,"props":709,"children":710},{},[711,720,728],{"type":19,"tag":245,"props":712,"children":713},{"align":214},[714],{"type":19,"tag":165,"props":715,"children":717},{"className":716},[],[718],{"type":25,"value":719},"checkBox_K",{"type":19,"tag":245,"props":721,"children":722},{"align":214},[723],{"type":19,"tag":165,"props":724,"children":726},{"className":725},[],[727],{"type":25,"value":677},{"type":19,"tag":245,"props":729,"children":730},{"align":214},[731],{"type":25,"value":732},"该控件位于选择车次类型的容器内，用于选择快车类型、对象名称自定义",{"type":19,"tag":208,"props":734,"children":735},{},[736,745,753],{"type":19,"tag":245,"props":737,"children":738},{"align":214},[739],{"type":19,"tag":165,"props":740,"children":742},{"className":741},[],[743],{"type":25,"value":744},"checkBox_T",{"type":19,"tag":245,"props":746,"children":747},{"align":214},[748],{"type":19,"tag":165,"props":749,"children":751},{"className":750},[],[752],{"type":25,"value":677},{"type":19,"tag":245,"props":754,"children":755},{"align":214},[756],{"type":25,"value":757},"该控件位于选择车次类型的容器内，用于选择特快类型、对象名称自定义",{"type":19,"tag":208,"props":759,"children":760},{},[761,770,778],{"type":19,"tag":245,"props":762,"children":763},{"align":214},[764],{"type":19,"tag":165,"props":765,"children":767},{"className":766},[],[768],{"type":25,"value":769},"checkBox_Z",{"type":19,"tag":245,"props":771,"children":772},{"align":214},[773],{"type":19,"tag":165,"props":774,"children":776},{"className":775},[],[777],{"type":25,"value":677},{"type":19,"tag":245,"props":779,"children":780},{"align":214},[781],{"type":25,"value":782},"该控件位于选择车次类型的容器内，用于选择直达类型、对象名称自定义",{"type":19,"tag":208,"props":784,"children":785},{},[786,795,803],{"type":19,"tag":245,"props":787,"children":788},{"align":214},[789],{"type":19,"tag":165,"props":790,"children":792},{"className":791},[],[793],{"type":25,"value":794},"label_type",{"type":19,"tag":245,"props":796,"children":797},{"align":214},[798],{"type":19,"tag":165,"props":799,"children":801},{"className":800},[],[802],{"type":25,"value":288},{"type":19,"tag":245,"props":804,"children":805},{"align":214},[806],{"type":25,"value":807},"该控件位于选择车次类型的容器内，用于显示“车次类型：”文字、对象名称自定义",{"type":19,"tag":208,"props":809,"children":810},{},[811,820,828],{"type":19,"tag":245,"props":812,"children":813},{"align":214},[814],{"type":19,"tag":165,"props":815,"children":817},{"className":816},[],[818],{"type":25,"value":819},"checkBox_O",{"type":19,"tag":245,"props":821,"children":822},{"align":214},[823],{"type":19,"tag":165,"props":824,"children":826},{"className":825},[],[827],{"type":25,"value":677},{"type":19,"tag":245,"props":829,"children":830},{"align":214},[831],{"type":25,"value":832},"该控件位于选择车次类型的容器内，用于选择其他类型、对象名称自定义",{"type":19,"tag":208,"props":834,"children":835},{},[836,845,853],{"type":19,"tag":245,"props":837,"children":838},{"align":214},[839],{"type":19,"tag":165,"props":840,"children":842},{"className":841},[],[843],{"type":25,"value":844},"checkBox_F",{"type":19,"tag":245,"props":846,"children":847},{"align":214},[848],{"type":19,"tag":165,"props":849,"children":851},{"className":850},[],[852],{"type":25,"value":677},{"type":19,"tag":245,"props":854,"children":855},{"align":214},[856],{"type":25,"value":857},"该控件位于选择车次类型的容器内，用于选择复兴号类型、对象名称自定义",{"type":19,"tag":208,"props":859,"children":860},{},[861,870,878],{"type":19,"tag":245,"props":862,"children":863},{"align":214},[864],{"type":19,"tag":165,"props":865,"children":867},{"className":866},[],[868],{"type":25,"value":869},"checkBox_EMU",{"type":19,"tag":245,"props":871,"children":872},{"align":214},[873],{"type":19,"tag":165,"props":874,"children":876},{"className":875},[],[877],{"type":25,"value":677},{"type":19,"tag":245,"props":879,"children":880},{"align":214},[881],{"type":25,"value":882},"该控件位于选择车次类型的容器内，用于选择智能动车组类型、对象名称自定义",{"type":19,"tag":208,"props":884,"children":885},{},[886,895,903],{"type":19,"tag":245,"props":887,"children":888},{"align":214},[889],{"type":19,"tag":165,"props":890,"children":892},{"className":891},[],[893],{"type":25,"value":894},"checkBox_ALL",{"type":19,"tag":245,"props":896,"children":897},{"align":214},[898],{"type":19,"tag":165,"props":899,"children":901},{"className":900},[],[902],{"type":25,"value":677},{"type":19,"tag":245,"props":904,"children":905},{"align":214},[906],{"type":25,"value":907},"该控件位于选择车次类型的容器内，用于选择全部类型、对象名称自定义",{"type":19,"tag":32,"props":909,"children":910},{},[911],{"type":19,"tag":50,"props":912,"children":915},{"alt":913,"src":914},"Pasted image 20250731170532","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731170532.png",[],{"type":19,"tag":917,"props":918,"children":919},"blockquote",{},[920],{"type":19,"tag":32,"props":921,"children":922},{},[923],{"type":25,"value":924},"说明：除了主窗体默认创建的QWidget控件外，其他每个QWidget就是一个显示区域的容器，都需要自行拖曳到主窗体当中，然后将每个区域对应的控件拖曳并摆放在当前的容器中即可。",{"type":19,"tag":32,"props":926,"children":927},{},[928],{"type":25,"value":929},"注意：在拖曳控件时可以根据控件边缘的蓝色调节点设置控件的位置与大小，如果需要修改非常精确的参数值可以在属性编辑器中进行设置也可以在生成后的Python代码中对窗体的详细参数进行修改。在设置控件文字时，可以选中控件然后在右侧的属性编辑器的text标签中进行设置，如图所示。",{"type":19,"tag":32,"props":931,"children":932},{},[933],{"type":19,"tag":50,"props":934,"children":937},{"alt":935,"src":936},"Pasted image 20250731171105","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731171105.png",[],{"type":19,"tag":32,"props":939,"children":940},{},[941],{"type":19,"tag":50,"props":942,"children":945},{"alt":943,"src":944},"Pasted image 20250731171239","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731171239.png",[],{"type":19,"tag":32,"props":947,"children":948},{},[949,951,957,959,965,967,973,975,981],{"type":25,"value":950},"5）窗体设计完成后，按下",{"type":19,"tag":165,"props":952,"children":954},{"className":953},[],[955],{"type":25,"value":956},"Ctrl+S",{"type":25,"value":958},"快捷键保存窗体设计文件名称为",{"type":19,"tag":165,"props":960,"children":962},{"className":961},[],[963],{"type":25,"value":964},"window.ui",{"type":25,"value":966},"，然后需要将该文件保存在当前项目的目录当中，再选中该文件单击右键依次选择",{"type":19,"tag":165,"props":968,"children":970},{"className":969},[],[971],{"type":25,"value":972},"External Tools → PyUIC",{"type":25,"value":974},"选项，将窗体设计的ui文件转换为",{"type":19,"tag":165,"props":976,"children":978},{"className":977},[],[979],{"type":25,"value":980},".py",{"type":25,"value":982},"文件，如图所示。",{"type":19,"tag":32,"props":984,"children":985},{},[986],{"type":19,"tag":50,"props":987,"children":990},{"alt":988,"src":989},"Pasted image 20250731171635","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731171635.png",[],{"type":19,"tag":32,"props":992,"children":993},{},[994],{"type":19,"tag":50,"props":995,"children":998},{"alt":996,"src":997},"Pasted image 20250731171708","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731171708.png",[],{"type":19,"tag":135,"props":1000,"children":1002},{"id":1001},"代码调试",[1003],{"type":25,"value":1001},{"type":19,"tag":32,"props":1005,"children":1006},{},[1007,1009,1015],{"type":25,"value":1008},"打开",{"type":19,"tag":165,"props":1010,"children":1012},{"className":1011},[],[1013],{"type":25,"value":1014},"window.py",{"type":25,"value":1016},"文件后，自动生成的代码中已经导入了PyQt5以及其内部的常用模块。PyQt5是一套Python绑定Digia QT5应用的框架，它可用于Python 2.x和3.x的版本中。它是功能最强大的GUI库之一，PyQt5的类别分为多个模块，常见的模块与概述如下表所示。",{"type":19,"tag":200,"props":1018,"children":1019},{},[1020,1041],{"type":19,"tag":204,"props":1021,"children":1022},{},[1023],{"type":19,"tag":208,"props":1024,"children":1025},{},[1026,1034],{"type":19,"tag":212,"props":1027,"children":1028},{"align":214},[1029],{"type":19,"tag":73,"props":1030,"children":1031},{},[1032],{"type":25,"value":1033},"模 块 名 称",{"type":19,"tag":212,"props":1035,"children":1036},{"align":214},[1037],{"type":19,"tag":73,"props":1038,"children":1039},{},[1040],{"type":25,"value":236},{"type":19,"tag":238,"props":1042,"children":1043},{},[1044,1057,1070,1083,1096,1109,1122,1135,1148,1161,1174],{"type":19,"tag":208,"props":1045,"children":1046},{},[1047,1052],{"type":19,"tag":245,"props":1048,"children":1049},{"align":214},[1050],{"type":25,"value":1051},"QtCore",{"type":19,"tag":245,"props":1053,"children":1054},{"align":214},[1055],{"type":25,"value":1056},"此模块用于处理时间、文件和目录、各种数据类型、流、URL、MIME类型、线程或进程",{"type":19,"tag":208,"props":1058,"children":1059},{},[1060,1065],{"type":19,"tag":245,"props":1061,"children":1062},{"align":214},[1063],{"type":25,"value":1064},"QtGui",{"type":19,"tag":245,"props":1066,"children":1067},{"align":214},[1068],{"type":25,"value":1069},"此模块包含类窗口系统集成、事件处理、二维图形、基本成像、字体和文本，以及一套完整的OpenGL和OpenGL ES的绑定",{"type":19,"tag":208,"props":1071,"children":1072},{},[1073,1078],{"type":19,"tag":245,"props":1074,"children":1075},{"align":214},[1076],{"type":25,"value":1077},"QtWidgets",{"type":19,"tag":245,"props":1079,"children":1080},{"align":214},[1081],{"type":25,"value":1082},"此模块中包含的类，提供了一组用于创建经典桌面风格用户界面的UI元素",{"type":19,"tag":208,"props":1084,"children":1085},{},[1086,1091],{"type":19,"tag":245,"props":1087,"children":1088},{"align":214},[1089],{"type":25,"value":1090},"QtMultimedia",{"type":19,"tag":245,"props":1092,"children":1093},{"align":214},[1094],{"type":25,"value":1095},"此模块中包含的类，用于处理多媒体内容和API来访问的相机、收音机功能",{"type":19,"tag":208,"props":1097,"children":1098},{},[1099,1104],{"type":19,"tag":245,"props":1100,"children":1101},{"align":214},[1102],{"type":25,"value":1103},"QtNetwork",{"type":19,"tag":245,"props":1105,"children":1106},{"align":214},[1107],{"type":25,"value":1108},"此模块中包含网络编程的类，通过这些类使网络编程更简单，更便携，便于TCP \u002F IP和UDP客户端和服务器的编码",{"type":19,"tag":208,"props":1110,"children":1111},{},[1112,1117],{"type":19,"tag":245,"props":1113,"children":1114},{"align":214},[1115],{"type":25,"value":1116},"QtPositioning",{"type":19,"tag":245,"props":1118,"children":1119},{"align":214},[1120],{"type":25,"value":1121},"此模块中包含的类，利用各种可能的来源，确定位置，包括卫星、Wi-Fi",{"type":19,"tag":208,"props":1123,"children":1124},{},[1125,1130],{"type":19,"tag":245,"props":1126,"children":1127},{"align":214},[1128],{"type":25,"value":1129},"QtWebSockets",{"type":19,"tag":245,"props":1131,"children":1132},{"align":214},[1133],{"type":25,"value":1134},"此模块中包含实现WebSocket协议的类",{"type":19,"tag":208,"props":1136,"children":1137},{},[1138,1143],{"type":19,"tag":245,"props":1139,"children":1140},{"align":214},[1141],{"type":25,"value":1142},"QtXml",{"type":19,"tag":245,"props":1144,"children":1145},{"align":214},[1146],{"type":25,"value":1147},"此模块中包含用于处理XML文件中的类，该模块为SAX和DOM API提供了解决方法",{"type":19,"tag":208,"props":1149,"children":1150},{},[1151,1156],{"type":19,"tag":245,"props":1152,"children":1153},{"align":214},[1154],{"type":25,"value":1155},"QtSvg",{"type":19,"tag":245,"props":1157,"children":1158},{"align":214},[1159],{"type":25,"value":1160},"此模块中提供了用于显示SVG文件内容的类，（SVG）是可缩放矢量图形，用于描述XML中的二维图形的一种格式",{"type":19,"tag":208,"props":1162,"children":1163},{},[1164,1169],{"type":19,"tag":245,"props":1165,"children":1166},{"align":214},[1167],{"type":25,"value":1168},"QtSql",{"type":19,"tag":245,"props":1170,"children":1171},{"align":214},[1172],{"type":25,"value":1173},"此模块提供了用于处理数据库的类",{"type":19,"tag":208,"props":1175,"children":1176},{},[1177,1182],{"type":19,"tag":245,"props":1178,"children":1179},{"align":214},[1180],{"type":25,"value":1181},"QtTest",{"type":19,"tag":245,"props":1183,"children":1184},{"align":214},[1185],{"type":25,"value":1186},"此模块包含的功能为pyqt5应用程序的单元测试",{"type":19,"tag":32,"props":1188,"children":1189},{},[1190],{"type":25,"value":1191},"下面通过代码来调试主窗体中各种控件的细节处理，以及相应的属性。具体步骤如下：",{"type":19,"tag":32,"props":1193,"children":1194},{},[1195,1197,1202,1204,1210],{"type":25,"value":1196},"1）打开",{"type":19,"tag":165,"props":1198,"children":1200},{"className":1199},[],[1201],{"type":25,"value":1014},{"type":25,"value":1203},"文件，在右侧代码区域的",{"type":19,"tag":165,"props":1205,"children":1207},{"className":1206},[],[1208],{"type":25,"value":1209},"setupUi()",{"type":25,"value":1211},"方法中修改主窗体的最大值与最小值，用于保持主窗体大小不变无法扩大或缩小。代码如下：",{"type":19,"tag":1213,"props":1214,"children":1218},"pre",{"className":1215,"code":1216,"language":1217,"meta":7,"style":7},"language-python shiki shiki-themes github-dark","MainWindow.setObjectName(\"MainWindow\")                 # 设置窗体对象名称  \nMainWindow.resize(1135, 806)                           # 设置窗体大小  \nMainWindow.setMinimumSize(QtCore.QSize(1135, 806))     # 主窗体最小值  \nMainWindow.setMaximumSize(QtCore.QSize(1135, 806))     # 主窗体最大值  \nself.centralwidget = QtWidgets.QWidget(MainWindow)     # 主窗体的widget控件  \nself.centralwidget.setObjectName(\"centralwidget\")      # 设置对象名称\n","python",[1219],{"type":19,"tag":165,"props":1220,"children":1221},{"__ignoreMap":7},[1222,1233,1242,1251,1260,1269],{"type":19,"tag":1223,"props":1224,"children":1227},"span",{"class":1225,"line":1226},"line",1,[1228],{"type":19,"tag":1223,"props":1229,"children":1230},{},[1231],{"type":25,"value":1232},"MainWindow.setObjectName(\"MainWindow\")                 # 设置窗体对象名称  \n",{"type":19,"tag":1223,"props":1234,"children":1236},{"class":1225,"line":1235},2,[1237],{"type":19,"tag":1223,"props":1238,"children":1239},{},[1240],{"type":25,"value":1241},"MainWindow.resize(1135, 806)                           # 设置窗体大小  \n",{"type":19,"tag":1223,"props":1243,"children":1245},{"class":1225,"line":1244},3,[1246],{"type":19,"tag":1223,"props":1247,"children":1248},{},[1249],{"type":25,"value":1250},"MainWindow.setMinimumSize(QtCore.QSize(1135, 806))     # 主窗体最小值  \n",{"type":19,"tag":1223,"props":1252,"children":1254},{"class":1225,"line":1253},4,[1255],{"type":19,"tag":1223,"props":1256,"children":1257},{},[1258],{"type":25,"value":1259},"MainWindow.setMaximumSize(QtCore.QSize(1135, 806))     # 主窗体最大值  \n",{"type":19,"tag":1223,"props":1261,"children":1263},{"class":1225,"line":1262},5,[1264],{"type":19,"tag":1223,"props":1265,"children":1266},{},[1267],{"type":25,"value":1268},"self.centralwidget = QtWidgets.QWidget(MainWindow)     # 主窗体的widget控件  \n",{"type":19,"tag":1223,"props":1270,"children":1272},{"class":1225,"line":1271},6,[1273],{"type":19,"tag":1223,"props":1274,"children":1275},{},[1276],{"type":25,"value":1277},"self.centralwidget.setObjectName(\"centralwidget\")      # 设置对象名称\n",{"type":19,"tag":32,"props":1279,"children":1280},{},[1281,1283,1288,1290,1296,1298,1304,1306,1312,1313,1319,1321,1326],{"type":25,"value":1282},"2）将图片资源",{"type":19,"tag":165,"props":1284,"children":1286},{"className":1285},[],[1287],{"type":25,"value":50},{"type":25,"value":1289},"文件夹复制到该项目中，然后导入",{"type":19,"tag":165,"props":1291,"children":1293},{"className":1292},[],[1294],{"type":25,"value":1295},"PyQt5.QtGui",{"type":25,"value":1297},"模块中的",{"type":19,"tag":165,"props":1299,"children":1301},{"className":1300},[],[1302],{"type":25,"value":1303},"QPalette",{"type":25,"value":1305},"、",{"type":19,"tag":165,"props":1307,"children":1309},{"className":1308},[],[1310],{"type":25,"value":1311},"QPixmap",{"type":25,"value":1305},{"type":19,"tag":165,"props":1314,"children":1316},{"className":1315},[],[1317],{"type":25,"value":1318},"QColor",{"type":25,"value":1320},"用于对控件设置背景图片，为对象名",{"type":19,"tag":165,"props":1322,"children":1324},{"className":1323},[],[1325],{"type":25,"value":279},{"type":25,"value":1327},"的Label控件设置背景图片，该控件用于显示顶部图片。关键代码如下：",{"type":19,"tag":1213,"props":1329,"children":1331},{"className":1215,"code":1330,"language":1217,"meta":7,"style":7},"# 导入QtGui模块  \nfrom PyQt5.QtGui import QPalette, QPixmap, QColor  \n# 通过label控件显示顶部图片  \nself.label_title_img = QtWidgets.QLabel(self.centralwidget)  \nself.label_title_img.setGeometry(QtCore.QRect(0, 0, 1131, 101))  \nself.label_title_img.setObjectName(\"label_title_img\")  \nbg1_bath = os.path.join(base_dir,'BG1.png')  \n# 打开顶部位图  \ntitle_img = QPixmap(bg1_bath)  \n# 设置调色板  \nself.label_title_img.setPixmap(title_img)  \n# 在设置pixmap后添加，让标签自适应图片大小  \nself.label_title_img.setScaledContents(True)\n",[1332],{"type":19,"tag":165,"props":1333,"children":1334},{"__ignoreMap":7},[1335,1343,1351,1359,1367,1375,1383,1392,1401,1410,1419,1428,1437],{"type":19,"tag":1223,"props":1336,"children":1337},{"class":1225,"line":1226},[1338],{"type":19,"tag":1223,"props":1339,"children":1340},{},[1341],{"type":25,"value":1342},"# 导入QtGui模块  \n",{"type":19,"tag":1223,"props":1344,"children":1345},{"class":1225,"line":1235},[1346],{"type":19,"tag":1223,"props":1347,"children":1348},{},[1349],{"type":25,"value":1350},"from PyQt5.QtGui import QPalette, QPixmap, QColor  \n",{"type":19,"tag":1223,"props":1352,"children":1353},{"class":1225,"line":1244},[1354],{"type":19,"tag":1223,"props":1355,"children":1356},{},[1357],{"type":25,"value":1358},"# 通过label控件显示顶部图片  \n",{"type":19,"tag":1223,"props":1360,"children":1361},{"class":1225,"line":1253},[1362],{"type":19,"tag":1223,"props":1363,"children":1364},{},[1365],{"type":25,"value":1366},"self.label_title_img = QtWidgets.QLabel(self.centralwidget)  \n",{"type":19,"tag":1223,"props":1368,"children":1369},{"class":1225,"line":1262},[1370],{"type":19,"tag":1223,"props":1371,"children":1372},{},[1373],{"type":25,"value":1374},"self.label_title_img.setGeometry(QtCore.QRect(0, 0, 1131, 101))  \n",{"type":19,"tag":1223,"props":1376,"children":1377},{"class":1225,"line":1271},[1378],{"type":19,"tag":1223,"props":1379,"children":1380},{},[1381],{"type":25,"value":1382},"self.label_title_img.setObjectName(\"label_title_img\")  \n",{"type":19,"tag":1223,"props":1384,"children":1386},{"class":1225,"line":1385},7,[1387],{"type":19,"tag":1223,"props":1388,"children":1389},{},[1390],{"type":25,"value":1391},"bg1_bath = os.path.join(base_dir,'BG1.png')  \n",{"type":19,"tag":1223,"props":1393,"children":1395},{"class":1225,"line":1394},8,[1396],{"type":19,"tag":1223,"props":1397,"children":1398},{},[1399],{"type":25,"value":1400},"# 打开顶部位图  \n",{"type":19,"tag":1223,"props":1402,"children":1404},{"class":1225,"line":1403},9,[1405],{"type":19,"tag":1223,"props":1406,"children":1407},{},[1408],{"type":25,"value":1409},"title_img = QPixmap(bg1_bath)  \n",{"type":19,"tag":1223,"props":1411,"children":1413},{"class":1225,"line":1412},10,[1414],{"type":19,"tag":1223,"props":1415,"children":1416},{},[1417],{"type":25,"value":1418},"# 设置调色板  \n",{"type":19,"tag":1223,"props":1420,"children":1422},{"class":1225,"line":1421},11,[1423],{"type":19,"tag":1223,"props":1424,"children":1425},{},[1426],{"type":25,"value":1427},"self.label_title_img.setPixmap(title_img)  \n",{"type":19,"tag":1223,"props":1429,"children":1431},{"class":1225,"line":1430},12,[1432],{"type":19,"tag":1223,"props":1433,"children":1434},{},[1435],{"type":25,"value":1436},"# 在设置pixmap后添加，让标签自适应图片大小  \n",{"type":19,"tag":1223,"props":1438,"children":1440},{"class":1225,"line":1439},13,[1441],{"type":19,"tag":1223,"props":1442,"children":1443},{},[1444],{"type":25,"value":1445},"self.label_title_img.setScaledContents(True)\n",{"type":19,"tag":32,"props":1447,"children":1448},{},[1449],{"type":25,"value":1450},"3）设置复选框部分widget控件的背景图片，该控件起到容器的作用，在设置背景图片时并没有Label控件那么简单，首先需要为该控件开启自动填充背景功能，然后创建调色板对象，指定调色板背景图片，最后为控件设置对应的调色板即可。关键代码如下：",{"type":19,"tag":1213,"props":1452,"children":1454},{"className":1215,"code":1453,"language":1217,"meta":7,"style":7},"# 查询部分的widget  \nself.widget_checkBox = QtWidgets.QWidget(self.centralwidget)  \nself.widget_checkBox.setGeometry(QtCore.QRect(0, 200, 1131, 51))  \n# 开启自动填充背景  \nself.widget_checkBox.setAutoFillBackground(True)  \nbg2_bath = os.path.join(base_dir,'BG2.png')  \n# 调色板类  \npalette = QPalette()  \n# 设置背景图片  \npalette.setBrush(QPalette.Background, QtGui.QBrush(QtGui.QPixmap(bg2_bath)))  \n# 为控件设置对应的调色板即可  \nself.widget_checkBox.setPalette(palette)  \nself.widget_checkBox.setObjectName(\"widget_checkBox\")\n",[1455],{"type":19,"tag":165,"props":1456,"children":1457},{"__ignoreMap":7},[1458,1466,1474,1482,1490,1498,1506,1514,1522,1530,1538,1546,1554],{"type":19,"tag":1223,"props":1459,"children":1460},{"class":1225,"line":1226},[1461],{"type":19,"tag":1223,"props":1462,"children":1463},{},[1464],{"type":25,"value":1465},"# 查询部分的widget  \n",{"type":19,"tag":1223,"props":1467,"children":1468},{"class":1225,"line":1235},[1469],{"type":19,"tag":1223,"props":1470,"children":1471},{},[1472],{"type":25,"value":1473},"self.widget_checkBox = QtWidgets.QWidget(self.centralwidget)  \n",{"type":19,"tag":1223,"props":1475,"children":1476},{"class":1225,"line":1244},[1477],{"type":19,"tag":1223,"props":1478,"children":1479},{},[1480],{"type":25,"value":1481},"self.widget_checkBox.setGeometry(QtCore.QRect(0, 200, 1131, 51))  \n",{"type":19,"tag":1223,"props":1483,"children":1484},{"class":1225,"line":1253},[1485],{"type":19,"tag":1223,"props":1486,"children":1487},{},[1488],{"type":25,"value":1489},"# 开启自动填充背景  \n",{"type":19,"tag":1223,"props":1491,"children":1492},{"class":1225,"line":1262},[1493],{"type":19,"tag":1223,"props":1494,"children":1495},{},[1496],{"type":25,"value":1497},"self.widget_checkBox.setAutoFillBackground(True)  \n",{"type":19,"tag":1223,"props":1499,"children":1500},{"class":1225,"line":1271},[1501],{"type":19,"tag":1223,"props":1502,"children":1503},{},[1504],{"type":25,"value":1505},"bg2_bath = os.path.join(base_dir,'BG2.png')  \n",{"type":19,"tag":1223,"props":1507,"children":1508},{"class":1225,"line":1385},[1509],{"type":19,"tag":1223,"props":1510,"children":1511},{},[1512],{"type":25,"value":1513},"# 调色板类  \n",{"type":19,"tag":1223,"props":1515,"children":1516},{"class":1225,"line":1394},[1517],{"type":19,"tag":1223,"props":1518,"children":1519},{},[1520],{"type":25,"value":1521},"palette = QPalette()  \n",{"type":19,"tag":1223,"props":1523,"children":1524},{"class":1225,"line":1403},[1525],{"type":19,"tag":1223,"props":1526,"children":1527},{},[1528],{"type":25,"value":1529},"# 设置背景图片  \n",{"type":19,"tag":1223,"props":1531,"children":1532},{"class":1225,"line":1412},[1533],{"type":19,"tag":1223,"props":1534,"children":1535},{},[1536],{"type":25,"value":1537},"palette.setBrush(QPalette.Background, QtGui.QBrush(QtGui.QPixmap(bg2_bath)))  \n",{"type":19,"tag":1223,"props":1539,"children":1540},{"class":1225,"line":1421},[1541],{"type":19,"tag":1223,"props":1542,"children":1543},{},[1544],{"type":25,"value":1545},"# 为控件设置对应的调色板即可  \n",{"type":19,"tag":1223,"props":1547,"children":1548},{"class":1225,"line":1430},[1549],{"type":19,"tag":1223,"props":1550,"children":1551},{},[1552],{"type":25,"value":1553},"self.widget_checkBox.setPalette(palette)  \n",{"type":19,"tag":1223,"props":1555,"children":1556},{"class":1225,"line":1439},[1557],{"type":19,"tag":1223,"props":1558,"children":1559},{},[1560],{"type":25,"value":1561},"self.widget_checkBox.setObjectName(\"widget_checkBox\")\n",{"type":19,"tag":917,"props":1563,"children":1564},{},[1565],{"type":19,"tag":32,"props":1566,"children":1567},{},[1568],{"type":25,"value":1569},"说明：根据以上两种设置背景图片的方法，分别为选择车次类型的widget控件与显示火车信息图片的Label控件设置背景图片。",{"type":19,"tag":32,"props":1571,"children":1572},{},[1573,1575,1580,1582,1588],{"type":25,"value":1574},"4）设置中间部分widget控件的背景图片，该控件起到容器的作用，在设置背景图片时，首先需要为该控件开启自动填充背景功能，要让图片完全展示且保持比例，你可以使用 ",{"type":19,"tag":165,"props":1576,"children":1578},{"className":1577},[],[1579],{"type":25,"value":1311},{"type":25,"value":1581}," 的 ",{"type":19,"tag":165,"props":1583,"children":1585},{"className":1584},[],[1586],{"type":25,"value":1587},"scaled",{"type":25,"value":1589}," 方法，并设置合适的缩放模式。然后创建调色板对象，指定调色板背景图片，最后为控件设置对应的调色板即可。关键代码如下：",{"type":19,"tag":1213,"props":1591,"children":1593},{"className":1215,"code":1592,"language":1217,"meta":7,"style":7},"self.label_train_img = QtWidgets.QLabel(self.centralwidget)  \nself.label_train_img.setGeometry(QtCore.QRect(0, 260, 1131, 71))  \nself.label_train_img.setObjectName(\"label_train_img\")  \nself.label_train_img.setAutoFillBackground(True)  \n# 加载图片  \nbg3_bath = os.path.join(base_dir, 'BG3.png')  \npixmap = QtGui.QPixmap(bg3_bath)  \n# 按标签大小缩放图片，保持比例，确保图片完全显示  \nscaled_pixmap = pixmap.scaled(  \n    self.label_train_img.size(),  \n    QtCore.Qt.KeepAspectRatio,      # 保持宽高比  \n    QtCore.Qt.SmoothTransformation  # 平滑缩放  \n)  \n# 设置调色板  \npalette = QPalette()  \npalette.setBrush(QPalette.Background, QtGui.QBrush(scaled_pixmap))  \nself.label_train_img.setPalette(palette)\n",[1594],{"type":19,"tag":165,"props":1595,"children":1596},{"__ignoreMap":7},[1597,1605,1613,1621,1629,1637,1645,1653,1661,1669,1677,1685,1693,1701,1709,1717,1726],{"type":19,"tag":1223,"props":1598,"children":1599},{"class":1225,"line":1226},[1600],{"type":19,"tag":1223,"props":1601,"children":1602},{},[1603],{"type":25,"value":1604},"self.label_train_img = QtWidgets.QLabel(self.centralwidget)  \n",{"type":19,"tag":1223,"props":1606,"children":1607},{"class":1225,"line":1235},[1608],{"type":19,"tag":1223,"props":1609,"children":1610},{},[1611],{"type":25,"value":1612},"self.label_train_img.setGeometry(QtCore.QRect(0, 260, 1131, 71))  \n",{"type":19,"tag":1223,"props":1614,"children":1615},{"class":1225,"line":1244},[1616],{"type":19,"tag":1223,"props":1617,"children":1618},{},[1619],{"type":25,"value":1620},"self.label_train_img.setObjectName(\"label_train_img\")  \n",{"type":19,"tag":1223,"props":1622,"children":1623},{"class":1225,"line":1253},[1624],{"type":19,"tag":1223,"props":1625,"children":1626},{},[1627],{"type":25,"value":1628},"self.label_train_img.setAutoFillBackground(True)  \n",{"type":19,"tag":1223,"props":1630,"children":1631},{"class":1225,"line":1262},[1632],{"type":19,"tag":1223,"props":1633,"children":1634},{},[1635],{"type":25,"value":1636},"# 加载图片  \n",{"type":19,"tag":1223,"props":1638,"children":1639},{"class":1225,"line":1271},[1640],{"type":19,"tag":1223,"props":1641,"children":1642},{},[1643],{"type":25,"value":1644},"bg3_bath = os.path.join(base_dir, 'BG3.png')  \n",{"type":19,"tag":1223,"props":1646,"children":1647},{"class":1225,"line":1385},[1648],{"type":19,"tag":1223,"props":1649,"children":1650},{},[1651],{"type":25,"value":1652},"pixmap = QtGui.QPixmap(bg3_bath)  \n",{"type":19,"tag":1223,"props":1654,"children":1655},{"class":1225,"line":1394},[1656],{"type":19,"tag":1223,"props":1657,"children":1658},{},[1659],{"type":25,"value":1660},"# 按标签大小缩放图片，保持比例，确保图片完全显示  \n",{"type":19,"tag":1223,"props":1662,"children":1663},{"class":1225,"line":1403},[1664],{"type":19,"tag":1223,"props":1665,"children":1666},{},[1667],{"type":25,"value":1668},"scaled_pixmap = pixmap.scaled(  \n",{"type":19,"tag":1223,"props":1670,"children":1671},{"class":1225,"line":1412},[1672],{"type":19,"tag":1223,"props":1673,"children":1674},{},[1675],{"type":25,"value":1676},"    self.label_train_img.size(),  \n",{"type":19,"tag":1223,"props":1678,"children":1679},{"class":1225,"line":1421},[1680],{"type":19,"tag":1223,"props":1681,"children":1682},{},[1683],{"type":25,"value":1684},"    QtCore.Qt.KeepAspectRatio,      # 保持宽高比  \n",{"type":19,"tag":1223,"props":1686,"children":1687},{"class":1225,"line":1430},[1688],{"type":19,"tag":1223,"props":1689,"children":1690},{},[1691],{"type":25,"value":1692},"    QtCore.Qt.SmoothTransformation  # 平滑缩放  \n",{"type":19,"tag":1223,"props":1694,"children":1695},{"class":1225,"line":1439},[1696],{"type":19,"tag":1223,"props":1697,"children":1698},{},[1699],{"type":25,"value":1700},")  \n",{"type":19,"tag":1223,"props":1702,"children":1704},{"class":1225,"line":1703},14,[1705],{"type":19,"tag":1223,"props":1706,"children":1707},{},[1708],{"type":25,"value":1418},{"type":19,"tag":1223,"props":1710,"children":1712},{"class":1225,"line":1711},15,[1713],{"type":19,"tag":1223,"props":1714,"children":1715},{},[1716],{"type":25,"value":1521},{"type":19,"tag":1223,"props":1718,"children":1720},{"class":1225,"line":1719},16,[1721],{"type":19,"tag":1223,"props":1722,"children":1723},{},[1724],{"type":25,"value":1725},"palette.setBrush(QPalette.Background, QtGui.QBrush(scaled_pixmap))  \n",{"type":19,"tag":1223,"props":1727,"children":1729},{"class":1225,"line":1728},17,[1730],{"type":19,"tag":1223,"props":1731,"children":1732},{},[1733],{"type":25,"value":1734},"self.label_train_img.setPalette(palette)\n",{"type":19,"tag":32,"props":1736,"children":1737},{},[1738,1740,1746],{"type":25,"value":1739},"5）通过代码修改窗体或控件文字时，需要在",{"type":19,"tag":165,"props":1741,"children":1743},{"className":1742},[],[1744],{"type":25,"value":1745},"retranslateUi()",{"type":25,"value":1747},"方法中进行设置，关键代码如下：",{"type":19,"tag":1213,"props":1749,"children":1751},{"className":1215,"code":1750,"language":1217,"meta":7,"style":7},"MainWindow.setWindowTitle(_translate(\"MainWindow\", \"MainWindow\"))  \nself.label.setText(_translate(\"MainWindow\", \"出发地：\"))  \nself.label_2.setText(_translate(\"MainWindow\", \"目的地：\"))  \nself.label_3.setText(_translate(\"MainWindow\", \"出发日：\"))  \nself.pushButton.setText(_translate(\"MainWindow\", \"查询\"))  \nself.label_4.setText(_translate(\"MainWindow\", \"车次类型：\"))  \nself.checkBox_G.setText(_translate(\"MainWindow\", \"GC-高铁\u002F城际\"))  \nself.checkBox_D.setText(_translate(\"MainWindow\", \"D-动车\"))  \nself.checkBox_Z.setText(_translate(\"MainWindow\", \"Z-直达\"))  \nself.checkBox_T.setText(_translate(\"MainWindow\", \"T-特快\"))  \nself.checkBox_K.setText(_translate(\"MainWindow\", \"K-快速\"))  \nself.checkBox_O.setText(_translate(\"MainWindow\", \"其他\"))  \nself.checkBox_F.setText(_translate(\"MainWindow\", \"复兴号\"))  \nself.checkBox_EMU.setText(_translate(\"MainWindow\", \"智能动车组\"))  \nself.checkBox_ALL.setText(_translate(\"MainWindow\", \"全部\"))\n",[1752],{"type":19,"tag":165,"props":1753,"children":1754},{"__ignoreMap":7},[1755,1763,1771,1779,1787,1795,1803,1811,1819,1827,1835,1843,1851,1859,1867],{"type":19,"tag":1223,"props":1756,"children":1757},{"class":1225,"line":1226},[1758],{"type":19,"tag":1223,"props":1759,"children":1760},{},[1761],{"type":25,"value":1762},"MainWindow.setWindowTitle(_translate(\"MainWindow\", \"MainWindow\"))  \n",{"type":19,"tag":1223,"props":1764,"children":1765},{"class":1225,"line":1235},[1766],{"type":19,"tag":1223,"props":1767,"children":1768},{},[1769],{"type":25,"value":1770},"self.label.setText(_translate(\"MainWindow\", \"出发地：\"))  \n",{"type":19,"tag":1223,"props":1772,"children":1773},{"class":1225,"line":1244},[1774],{"type":19,"tag":1223,"props":1775,"children":1776},{},[1777],{"type":25,"value":1778},"self.label_2.setText(_translate(\"MainWindow\", \"目的地：\"))  \n",{"type":19,"tag":1223,"props":1780,"children":1781},{"class":1225,"line":1253},[1782],{"type":19,"tag":1223,"props":1783,"children":1784},{},[1785],{"type":25,"value":1786},"self.label_3.setText(_translate(\"MainWindow\", \"出发日：\"))  \n",{"type":19,"tag":1223,"props":1788,"children":1789},{"class":1225,"line":1262},[1790],{"type":19,"tag":1223,"props":1791,"children":1792},{},[1793],{"type":25,"value":1794},"self.pushButton.setText(_translate(\"MainWindow\", \"查询\"))  \n",{"type":19,"tag":1223,"props":1796,"children":1797},{"class":1225,"line":1271},[1798],{"type":19,"tag":1223,"props":1799,"children":1800},{},[1801],{"type":25,"value":1802},"self.label_4.setText(_translate(\"MainWindow\", \"车次类型：\"))  \n",{"type":19,"tag":1223,"props":1804,"children":1805},{"class":1225,"line":1385},[1806],{"type":19,"tag":1223,"props":1807,"children":1808},{},[1809],{"type":25,"value":1810},"self.checkBox_G.setText(_translate(\"MainWindow\", \"GC-高铁\u002F城际\"))  \n",{"type":19,"tag":1223,"props":1812,"children":1813},{"class":1225,"line":1394},[1814],{"type":19,"tag":1223,"props":1815,"children":1816},{},[1817],{"type":25,"value":1818},"self.checkBox_D.setText(_translate(\"MainWindow\", \"D-动车\"))  \n",{"type":19,"tag":1223,"props":1820,"children":1821},{"class":1225,"line":1403},[1822],{"type":19,"tag":1223,"props":1823,"children":1824},{},[1825],{"type":25,"value":1826},"self.checkBox_Z.setText(_translate(\"MainWindow\", \"Z-直达\"))  \n",{"type":19,"tag":1223,"props":1828,"children":1829},{"class":1225,"line":1412},[1830],{"type":19,"tag":1223,"props":1831,"children":1832},{},[1833],{"type":25,"value":1834},"self.checkBox_T.setText(_translate(\"MainWindow\", \"T-特快\"))  \n",{"type":19,"tag":1223,"props":1836,"children":1837},{"class":1225,"line":1421},[1838],{"type":19,"tag":1223,"props":1839,"children":1840},{},[1841],{"type":25,"value":1842},"self.checkBox_K.setText(_translate(\"MainWindow\", \"K-快速\"))  \n",{"type":19,"tag":1223,"props":1844,"children":1845},{"class":1225,"line":1430},[1846],{"type":19,"tag":1223,"props":1847,"children":1848},{},[1849],{"type":25,"value":1850},"self.checkBox_O.setText(_translate(\"MainWindow\", \"其他\"))  \n",{"type":19,"tag":1223,"props":1852,"children":1853},{"class":1225,"line":1439},[1854],{"type":19,"tag":1223,"props":1855,"children":1856},{},[1857],{"type":25,"value":1858},"self.checkBox_F.setText(_translate(\"MainWindow\", \"复兴号\"))  \n",{"type":19,"tag":1223,"props":1860,"children":1861},{"class":1225,"line":1703},[1862],{"type":19,"tag":1223,"props":1863,"children":1864},{},[1865],{"type":25,"value":1866},"self.checkBox_EMU.setText(_translate(\"MainWindow\", \"智能动车组\"))  \n",{"type":19,"tag":1223,"props":1868,"children":1869},{"class":1225,"line":1711},[1870],{"type":19,"tag":1223,"props":1871,"children":1872},{},[1873],{"type":25,"value":1874},"self.checkBox_ALL.setText(_translate(\"MainWindow\", \"全部\"))\n",{"type":19,"tag":32,"props":1876,"children":1877},{},[1878,1880,1886],{"type":25,"value":1879},"6）导入sys模块，然后在代码块的最外层创建",{"type":19,"tag":165,"props":1881,"children":1883},{"className":1882},[],[1884],{"type":25,"value":1885},"show_MainWindow()",{"type":25,"value":1887},"方法，该方法用于显示窗体。关键代码如下：",{"type":19,"tag":1213,"props":1889,"children":1891},{"className":1215,"code":1890,"language":1217,"meta":7,"style":7},"def show_MainWindow():  \n    app = QtWidgets.QApplication(sys.argv)   # 实例化QApplication类，作为GUI主程序入口  \n    MainWindow = QtWidgets.QMainWindow()     # 创建MainWindow类  \n    ui = Ui_MainWindow()                     # 实例UI类  \n    ui.setupUi(MainWindow)                   # 设置窗体UI  \n    MainWindow.show()                        # 显示窗体  \n    sys.exit(app.exec_())                    # 当窗口创建完成，需要结束主循环过程\n",[1892],{"type":19,"tag":165,"props":1893,"children":1894},{"__ignoreMap":7},[1895,1903,1911,1919,1927,1935,1943],{"type":19,"tag":1223,"props":1896,"children":1897},{"class":1225,"line":1226},[1898],{"type":19,"tag":1223,"props":1899,"children":1900},{},[1901],{"type":25,"value":1902},"def show_MainWindow():  \n",{"type":19,"tag":1223,"props":1904,"children":1905},{"class":1225,"line":1235},[1906],{"type":19,"tag":1223,"props":1907,"children":1908},{},[1909],{"type":25,"value":1910},"    app = QtWidgets.QApplication(sys.argv)   # 实例化QApplication类，作为GUI主程序入口  \n",{"type":19,"tag":1223,"props":1912,"children":1913},{"class":1225,"line":1244},[1914],{"type":19,"tag":1223,"props":1915,"children":1916},{},[1917],{"type":25,"value":1918},"    MainWindow = QtWidgets.QMainWindow()     # 创建MainWindow类  \n",{"type":19,"tag":1223,"props":1920,"children":1921},{"class":1225,"line":1253},[1922],{"type":19,"tag":1223,"props":1923,"children":1924},{},[1925],{"type":25,"value":1926},"    ui = Ui_MainWindow()                     # 实例UI类  \n",{"type":19,"tag":1223,"props":1928,"children":1929},{"class":1225,"line":1262},[1930],{"type":19,"tag":1223,"props":1931,"children":1932},{},[1933],{"type":25,"value":1934},"    ui.setupUi(MainWindow)                   # 设置窗体UI  \n",{"type":19,"tag":1223,"props":1936,"children":1937},{"class":1225,"line":1271},[1938],{"type":19,"tag":1223,"props":1939,"children":1940},{},[1941],{"type":25,"value":1942},"    MainWindow.show()                        # 显示窗体  \n",{"type":19,"tag":1223,"props":1944,"children":1945},{"class":1225,"line":1385},[1946],{"type":19,"tag":1223,"props":1947,"children":1948},{},[1949],{"type":25,"value":1950},"    sys.exit(app.exec_())                    # 当窗口创建完成，需要结束主循环过程\n",{"type":19,"tag":917,"props":1952,"children":1953},{},[1954],{"type":19,"tag":32,"props":1955,"children":1956},{},[1957],{"type":25,"value":1958},"说明：sys模块是python自带的模块，该模块提供了一系列有关Python运行环境的变量和函数。sys模块的常见用法与含义如表7所示。",{"type":19,"tag":32,"props":1960,"children":1961},{},[1962],{"type":19,"tag":73,"props":1963,"children":1964},{},[1965],{"type":25,"value":1966},"sys模块的常见用法",{"type":19,"tag":200,"props":1968,"children":1969},{},[1970,1991],{"type":19,"tag":204,"props":1971,"children":1972},{},[1973],{"type":19,"tag":208,"props":1974,"children":1975},{},[1976,1984],{"type":19,"tag":212,"props":1977,"children":1978},{"align":214},[1979],{"type":19,"tag":73,"props":1980,"children":1981},{},[1982],{"type":25,"value":1983},"常 见 用 法",{"type":19,"tag":212,"props":1985,"children":1986},{"align":214},[1987],{"type":19,"tag":73,"props":1988,"children":1989},{},[1990],{"type":25,"value":236},{"type":19,"tag":238,"props":1992,"children":1993},{},[1994,2011,2028,2045,2062,2079],{"type":19,"tag":208,"props":1995,"children":1996},{},[1997,2006],{"type":19,"tag":245,"props":1998,"children":1999},{"align":214},[2000],{"type":19,"tag":165,"props":2001,"children":2003},{"className":2002},[],[2004],{"type":25,"value":2005},"sys.argv",{"type":19,"tag":245,"props":2007,"children":2008},{"align":214},[2009],{"type":25,"value":2010},"该方法用于获取当前正在执行的命令行参数的参数列表",{"type":19,"tag":208,"props":2012,"children":2013},{},[2014,2023],{"type":19,"tag":245,"props":2015,"children":2016},{"align":214},[2017],{"type":19,"tag":165,"props":2018,"children":2020},{"className":2019},[],[2021],{"type":25,"value":2022},"sys.path",{"type":19,"tag":245,"props":2024,"children":2025},{"align":214},[2026],{"type":25,"value":2027},"该方法用于获取指定模块路径的字符串集合",{"type":19,"tag":208,"props":2029,"children":2030},{},[2031,2040],{"type":19,"tag":245,"props":2032,"children":2033},{"align":214},[2034],{"type":19,"tag":165,"props":2035,"children":2037},{"className":2036},[],[2038],{"type":25,"value":2039},"sys.exit()",{"type":19,"tag":245,"props":2041,"children":2042},{"align":214},[2043],{"type":25,"value":2044},"该方法用于退出程序，当参数非0时，会引发一个SystemExit异常，从而可以在主程序中捕获该异常",{"type":19,"tag":208,"props":2046,"children":2047},{},[2048,2057],{"type":19,"tag":245,"props":2049,"children":2050},{"align":214},[2051],{"type":19,"tag":165,"props":2052,"children":2054},{"className":2053},[],[2055],{"type":25,"value":2056},"sys.platform",{"type":19,"tag":245,"props":2058,"children":2059},{"align":214},[2060],{"type":25,"value":2061},"该方法用于获取当前系统平台",{"type":19,"tag":208,"props":2063,"children":2064},{},[2065,2074],{"type":19,"tag":245,"props":2066,"children":2067},{"align":214},[2068],{"type":19,"tag":165,"props":2069,"children":2071},{"className":2070},[],[2072],{"type":25,"value":2073},"sys.modules",{"type":19,"tag":245,"props":2075,"children":2076},{"align":214},[2077],{"type":25,"value":2078},"该方法是用于加载模块的字典，每当程序员导入新的模块时，sys.modules将自动记录该模块。当相同模块第二次导入时Python将从该字典中进行查询，从而加快程序的运行速度",{"type":19,"tag":208,"props":2080,"children":2081},{},[2082,2091],{"type":19,"tag":245,"props":2083,"children":2084},{"align":214},[2085],{"type":19,"tag":165,"props":2086,"children":2088},{"className":2087},[],[2089],{"type":25,"value":2090},"sys.getdefaultencoding()",{"type":19,"tag":245,"props":2092,"children":2093},{"align":214},[2094],{"type":25,"value":2095},"该方法用于获取当前系统编码方式",{"type":19,"tag":32,"props":2097,"children":2098},{},[2099,2101,2106],{"type":25,"value":2100},"6）在代码块的最外层模拟Python的程序入口，然后调用显示窗体的",{"type":19,"tag":165,"props":2102,"children":2104},{"className":2103},[],[2105],{"type":25,"value":1885},{"type":25,"value":2107},"方法。关键代码如下：",{"type":19,"tag":1213,"props":2109,"children":2111},{"className":1215,"code":2110,"language":1217,"meta":7,"style":7},"if __name__ == \"__main__\":  \n    show_MainWindow()\n",[2112],{"type":19,"tag":165,"props":2113,"children":2114},{"__ignoreMap":7},[2115,2123],{"type":19,"tag":1223,"props":2116,"children":2117},{"class":1225,"line":1226},[2118],{"type":19,"tag":1223,"props":2119,"children":2120},{},[2121],{"type":25,"value":2122},"if __name__ == \"__main__\":  \n",{"type":19,"tag":1223,"props":2124,"children":2125},{"class":1225,"line":1235},[2126],{"type":19,"tag":1223,"props":2127,"children":2128},{},[2129],{"type":25,"value":2130},"    show_MainWindow()\n",{"type":19,"tag":32,"props":2132,"children":2133},{},[2134],{"type":25,"value":2135},"执行该python文件将显示如下主界面：",{"type":19,"tag":32,"props":2137,"children":2138},{},[2139],{"type":19,"tag":50,"props":2140,"children":2143},{"alt":2141,"src":2142},"Pasted image 20250801225319","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250801225319.png",[],{"type":19,"tag":20,"props":2145,"children":2147},{"id":2146},"分析网页请求参数",[2148],{"type":25,"value":2146},{"type":19,"tag":28,"props":2150,"children":2151},{},[],{"type":19,"tag":32,"props":2153,"children":2154},{},[2155],{"type":25,"value":2156},"既然是爬票，那么一定需要一个爬取的对象，本项目实战将通过12306中国铁路客户服务中心所提供的查票请求地址获取火车票的相关信息。在发送请求时，地址中需要填写必要的参数否则后台将无法返回前台所需要的正确信息，所以首先需要分析网页请求参数，具体步骤如下：",{"type":19,"tag":32,"props":2158,"children":2159},{},[2160,2162,2168,2170,2176,2178,2184],{"type":25,"value":2161},"1）浏览器打开12306官方网站",{"type":19,"tag":165,"props":2163,"children":2165},{"className":2164},[],[2166],{"type":25,"value":2167},"https:\u002F\u002Fwww.12306.cn\u002Findex\u002F",{"type":25,"value":2169},"，输入出发地与目的地，出发日期默认即可，点击查询后会发现新打开了一个页面",{"type":19,"tag":165,"props":2171,"children":2173},{"className":2172},[],[2174],{"type":25,"value":2175},"https:\u002F\u002Fkyfw.12306.cn\u002Fotn\u002FleftTicket\u002Finit",{"type":25,"value":2177},"，这个页面才是我们的目标页面。输入出发地目的地及日期后，按下",{"type":19,"tag":165,"props":2179,"children":2181},{"className":2180},[],[2182],{"type":25,"value":2183},"F12",{"type":25,"value":2185},"快捷键打开网络监视器，然后单击查询按钮，在网络监视器中将显示对应的网络请求，如图所示。",{"type":19,"tag":32,"props":2187,"children":2188},{},[2189,2194],{"type":19,"tag":50,"props":2190,"children":2193},{"alt":2191,"src":2192},"Pasted image 20250731155223","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731155223.png",[],{"type":19,"tag":50,"props":2195,"children":2198},{"alt":2196,"src":2197},"Pasted image 20250731155548","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731155548.png",[],{"type":19,"tag":32,"props":2200,"children":2201},{},[2202],{"type":25,"value":2203},"2）单击网络请求将显示请求细节的窗口，在该窗口中默认会显示消息头的相关数据，此处可以获取完整的请求地址，如图所示。",{"type":19,"tag":32,"props":2205,"children":2206},{},[2207],{"type":19,"tag":50,"props":2208,"children":2211},{"alt":2209,"src":2210},"Pasted image 20250731155738","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731155738.png",[],{"type":19,"tag":917,"props":2213,"children":2214},{},[2215],{"type":19,"tag":32,"props":2216,"children":2217},{},[2218],{"type":25,"value":2219},"注意：随着12306官方网站的更新，请求地址会发生改变，要以当时获取的地址为准。",{"type":19,"tag":32,"props":2221,"children":2222},{},[2223],{"type":25,"value":2224},"3）在请求地址的下方，请求头信息当中获取该请求地址中的Cookie信息，如图所示：",{"type":19,"tag":32,"props":2226,"children":2227},{},[2228],{"type":19,"tag":50,"props":2229,"children":2232},{"alt":2230,"src":2231},"Pasted image 20250731155955","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731155955.png",[],{"type":19,"tag":32,"props":2234,"children":2235},{},[2236],{"type":25,"value":2237},"4）在请求地址的上方选择参数选项，将显示该请求地址中的必要参数，如图所示：",{"type":19,"tag":32,"props":2239,"children":2240},{},[2241],{"type":19,"tag":50,"props":2242,"children":2245},{"alt":2243,"src":2244},"Pasted image 20250731160453","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731160453.png",[],{"type":19,"tag":20,"props":2247,"children":2249},{"id":2248},"下载站名文件",[2250],{"type":25,"value":2248},{"type":19,"tag":28,"props":2252,"children":2253},{},[],{"type":19,"tag":32,"props":2255,"children":2256},{},[2257],{"type":25,"value":2258},"得到了请求地址与请求参数后，可以发现请求参数中的出发地与目的地均为车站名的英文缩写。而这个英文缩写的字母是通过输入中文车站名转换而来的，所以需要在网页中仔细查找是否有将车站名自动转换为英文缩写的请求信息，具体步骤如下：",{"type":19,"tag":32,"props":2260,"children":2261},{},[2262,2264,2270,2272,2278],{"type":25,"value":2263},"1）关闭并重新打开网络监视器，然后按下快捷键",{"type":19,"tag":165,"props":2265,"children":2267},{"className":2266},[],[2268],{"type":25,"value":2269},"F5",{"type":25,"value":2271},"进行余票查询网页的刷新，此时在网络监视器中选择类型为",{"type":19,"tag":165,"props":2273,"children":2275},{"className":2274},[],[2276],{"type":25,"value":2277},"js",{"type":25,"value":2279},"的网络请求。在文件类型中仔细分析文件内容是否有，与车站名相关的信息如图所示。",{"type":19,"tag":32,"props":2281,"children":2282},{},[2283],{"type":19,"tag":50,"props":2284,"children":2287},{"alt":2285,"src":2286},"Pasted image 20250731211908","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731211908.png",[],{"type":19,"tag":917,"props":2289,"children":2290},{},[2291],{"type":19,"tag":32,"props":2292,"children":2293},{},[2294],{"type":25,"value":2295},"说明：在分析信息位置时，查询按钮仅仅实现了发送查票的网络请求，而并没有发现将文字转换为车站名缩写的相关处理，此时可以判断在进入余票查询页面时就已经得到了将车站名转换为英文缩写的相关信息，所以可以刷新页面查看网络监视器中的网络请求。",{"type":19,"tag":32,"props":2297,"children":2298},{},[2299],{"type":25,"value":2300},"2）选中与车站名相关的网络请求，在请求细节中找到该请求的完整地址。然后在网页中打开该地址测试返回数据，如图所示。",{"type":19,"tag":32,"props":2302,"children":2303},{},[2304],{"type":19,"tag":50,"props":2305,"children":2308},{"alt":2306,"src":2307},"Pasted image 20250731212159","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731212159.png",[],{"type":19,"tag":917,"props":2310,"children":2311},{},[2312],{"type":19,"tag":32,"props":2313,"children":2314},{},[2315,2317,2323],{"type":25,"value":2316},"说明：看到返回的车站名信息，此时可以确认根据该信息可以进行车站名汉字与对应的英文缩写进行转换。例如，可以在该条信息中找到天水南对应的是",{"type":19,"tag":165,"props":2318,"children":2320},{"className":2319},[],[2321],{"type":25,"value":2322},"TIJ",{"type":25,"value":2324},"。由于该条信息并没有自动转换的功能，所以需要将该信息以文件的方式保存在项目中。当需要转换时在文件中查找对应的英文缩写即可。",{"type":19,"tag":32,"props":2326,"children":2327},{},[2328,2330,2336],{"type":25,"value":2329},"3）打开PyCharm开发工具，在项目目录中右键菜单依次选择New → Python File，创建一个名称为",{"type":19,"tag":165,"props":2331,"children":2333},{"className":2332},[],[2334],{"type":25,"value":2335},"get_stations.py",{"type":25,"value":2337},"文件，然后确保已成功安装requests模块即可。",{"type":19,"tag":32,"props":2339,"children":2340},{},[2341,2343,2348,2350,2356,2358,2364,2366,2372,2374,2380],{"type":25,"value":2342},"4）在",{"type":19,"tag":165,"props":2344,"children":2346},{"className":2345},[],[2347],{"type":25,"value":2335},{"type":25,"value":2349},"文件中分别导入",{"type":19,"tag":165,"props":2351,"children":2353},{"className":2352},[],[2354],{"type":25,"value":2355},"requests",{"type":25,"value":2357},"模块、",{"type":19,"tag":165,"props":2359,"children":2361},{"className":2360},[],[2362],{"type":25,"value":2363},"re",{"type":25,"value":2365},"模块及",{"type":19,"tag":165,"props":2367,"children":2369},{"className":2368},[],[2370],{"type":25,"value":2371},"os",{"type":25,"value":2373},"模块，然后创建",{"type":19,"tag":165,"props":2375,"children":2377},{"className":2376},[],[2378],{"type":25,"value":2379},"getStation()",{"type":25,"value":2381},"方法，该方法用于发送获取地址信息的网络请求，并将返回的数据转换为需要的类型。关键代码如下：",{"type":19,"tag":1213,"props":2383,"children":2385},{"className":1215,"code":2384,"language":1217,"meta":7,"style":7},"stat = {}                                       # 设定一个全局变量存放地址转换字典信息\ndef getStation():  \n    # 发送请求获取所有车站名称，通过输入的站名转换为查询地址的参数  \n    url = 'https:\u002F\u002Fkyfw.12306.cn\u002Fotn\u002Fresources\u002Fjs\u002Fframework\u002Fstation_name.js?station_version=1.9346'  \n    response = requests.get(url, verify=True) # 请求并进行验证  \n    # 获取需要的车站名称  \n    stations = re.findall(r'([\\u4e00-\\u9fa5]+)\\|([A-Z]+)', response.text)  \n    stations = dict((stations))                  # 转换为字典类型  \n    global stat  \n    stat = stations                              # 将结果存入全局变量stat  \n    stations = str(stations)                     # 转换为字符串类型否则无法写入文件  \n    write(stations)                              # 调用写入方法\n",[2386],{"type":19,"tag":165,"props":2387,"children":2388},{"__ignoreMap":7},[2389,2397,2405,2413,2421,2429,2437,2445,2453,2461,2469,2477],{"type":19,"tag":1223,"props":2390,"children":2391},{"class":1225,"line":1226},[2392],{"type":19,"tag":1223,"props":2393,"children":2394},{},[2395],{"type":25,"value":2396},"stat = {}                                       # 设定一个全局变量存放地址转换字典信息\n",{"type":19,"tag":1223,"props":2398,"children":2399},{"class":1225,"line":1235},[2400],{"type":19,"tag":1223,"props":2401,"children":2402},{},[2403],{"type":25,"value":2404},"def getStation():  \n",{"type":19,"tag":1223,"props":2406,"children":2407},{"class":1225,"line":1244},[2408],{"type":19,"tag":1223,"props":2409,"children":2410},{},[2411],{"type":25,"value":2412},"    # 发送请求获取所有车站名称，通过输入的站名转换为查询地址的参数  \n",{"type":19,"tag":1223,"props":2414,"children":2415},{"class":1225,"line":1253},[2416],{"type":19,"tag":1223,"props":2417,"children":2418},{},[2419],{"type":25,"value":2420},"    url = 'https:\u002F\u002Fkyfw.12306.cn\u002Fotn\u002Fresources\u002Fjs\u002Fframework\u002Fstation_name.js?station_version=1.9346'  \n",{"type":19,"tag":1223,"props":2422,"children":2423},{"class":1225,"line":1262},[2424],{"type":19,"tag":1223,"props":2425,"children":2426},{},[2427],{"type":25,"value":2428},"    response = requests.get(url, verify=True) # 请求并进行验证  \n",{"type":19,"tag":1223,"props":2430,"children":2431},{"class":1225,"line":1271},[2432],{"type":19,"tag":1223,"props":2433,"children":2434},{},[2435],{"type":25,"value":2436},"    # 获取需要的车站名称  \n",{"type":19,"tag":1223,"props":2438,"children":2439},{"class":1225,"line":1385},[2440],{"type":19,"tag":1223,"props":2441,"children":2442},{},[2443],{"type":25,"value":2444},"    stations = re.findall(r'([\\u4e00-\\u9fa5]+)\\|([A-Z]+)', response.text)  \n",{"type":19,"tag":1223,"props":2446,"children":2447},{"class":1225,"line":1394},[2448],{"type":19,"tag":1223,"props":2449,"children":2450},{},[2451],{"type":25,"value":2452},"    stations = dict((stations))                  # 转换为字典类型  \n",{"type":19,"tag":1223,"props":2454,"children":2455},{"class":1225,"line":1403},[2456],{"type":19,"tag":1223,"props":2457,"children":2458},{},[2459],{"type":25,"value":2460},"    global stat  \n",{"type":19,"tag":1223,"props":2462,"children":2463},{"class":1225,"line":1412},[2464],{"type":19,"tag":1223,"props":2465,"children":2466},{},[2467],{"type":25,"value":2468},"    stat = stations                              # 将结果存入全局变量stat  \n",{"type":19,"tag":1223,"props":2470,"children":2471},{"class":1225,"line":1421},[2472],{"type":19,"tag":1223,"props":2473,"children":2474},{},[2475],{"type":25,"value":2476},"    stations = str(stations)                     # 转换为字符串类型否则无法写入文件  \n",{"type":19,"tag":1223,"props":2478,"children":2479},{"class":1225,"line":1430},[2480],{"type":19,"tag":1223,"props":2481,"children":2482},{},[2483],{"type":25,"value":2484},"    write(stations)                              # 调用写入方法\n",{"type":19,"tag":917,"props":2486,"children":2487},{},[2488],{"type":19,"tag":32,"props":2489,"children":2490},{},[2491],{"type":25,"value":2492},"说明：requests模块为第三方模块，该模块主要用于处理网络请求；re模块为Python自带的模块，主要通过正则表达式匹配并处理相应的字符串；os模块为Python自带的模块，主要用于判断某个路径下的某个文件。",{"type":19,"tag":32,"props":2494,"children":2495},{},[2496],{"type":25,"value":2219},{"type":19,"tag":32,"props":2498,"children":2499},{},[2500,2502,2508,2510,2516,2518,2524],{"type":25,"value":2501},"5）分别创建",{"type":19,"tag":165,"props":2503,"children":2505},{"className":2504},[],[2506],{"type":25,"value":2507},"write()",{"type":25,"value":2509},"方法、",{"type":19,"tag":165,"props":2511,"children":2513},{"className":2512},[],[2514],{"type":25,"value":2515},"read()",{"type":25,"value":2517},"方法及",{"type":19,"tag":165,"props":2519,"children":2521},{"className":2520},[],[2522],{"type":25,"value":2523},"isStations()",{"type":25,"value":2525},"方法，分别用于写入文件、读取文件以及判断车站文件是否存在，代码如下：",{"type":19,"tag":1213,"props":2527,"children":2529},{"className":1215,"code":2528,"language":1217,"meta":7,"style":7},"def write(stations):  \n    file =open('stations.text','w',encoding='utf_8_sig')   # 以写模式打开文件  \n    file.write(stations)                                   # 写入文件  \n    file.close()  \n  \ndef read():  \n    file =open('stations.text','r',encoding='utf_8_sig')   # 以写模式打开文件  \n    data = file.readline()                                 # 读取文件  \n    file.close()  \n    return data  \n  \ndef isStations():  \n    isStations = os.path.exists('stations.text')           # 判断车站文件是否存在  \n    return isStations\n",[2530],{"type":19,"tag":165,"props":2531,"children":2532},{"__ignoreMap":7},[2533,2541,2549,2557,2565,2573,2581,2589,2597,2604,2612,2619,2627,2635],{"type":19,"tag":1223,"props":2534,"children":2535},{"class":1225,"line":1226},[2536],{"type":19,"tag":1223,"props":2537,"children":2538},{},[2539],{"type":25,"value":2540},"def write(stations):  \n",{"type":19,"tag":1223,"props":2542,"children":2543},{"class":1225,"line":1235},[2544],{"type":19,"tag":1223,"props":2545,"children":2546},{},[2547],{"type":25,"value":2548},"    file =open('stations.text','w',encoding='utf_8_sig')   # 以写模式打开文件  \n",{"type":19,"tag":1223,"props":2550,"children":2551},{"class":1225,"line":1244},[2552],{"type":19,"tag":1223,"props":2553,"children":2554},{},[2555],{"type":25,"value":2556},"    file.write(stations)                                   # 写入文件  \n",{"type":19,"tag":1223,"props":2558,"children":2559},{"class":1225,"line":1253},[2560],{"type":19,"tag":1223,"props":2561,"children":2562},{},[2563],{"type":25,"value":2564},"    file.close()  \n",{"type":19,"tag":1223,"props":2566,"children":2567},{"class":1225,"line":1262},[2568],{"type":19,"tag":1223,"props":2569,"children":2570},{},[2571],{"type":25,"value":2572},"  \n",{"type":19,"tag":1223,"props":2574,"children":2575},{"class":1225,"line":1271},[2576],{"type":19,"tag":1223,"props":2577,"children":2578},{},[2579],{"type":25,"value":2580},"def read():  \n",{"type":19,"tag":1223,"props":2582,"children":2583},{"class":1225,"line":1385},[2584],{"type":19,"tag":1223,"props":2585,"children":2586},{},[2587],{"type":25,"value":2588},"    file =open('stations.text','r',encoding='utf_8_sig')   # 以写模式打开文件  \n",{"type":19,"tag":1223,"props":2590,"children":2591},{"class":1225,"line":1394},[2592],{"type":19,"tag":1223,"props":2593,"children":2594},{},[2595],{"type":25,"value":2596},"    data = file.readline()                                 # 读取文件  \n",{"type":19,"tag":1223,"props":2598,"children":2599},{"class":1225,"line":1403},[2600],{"type":19,"tag":1223,"props":2601,"children":2602},{},[2603],{"type":25,"value":2564},{"type":19,"tag":1223,"props":2605,"children":2606},{"class":1225,"line":1412},[2607],{"type":19,"tag":1223,"props":2608,"children":2609},{},[2610],{"type":25,"value":2611},"    return data  \n",{"type":19,"tag":1223,"props":2613,"children":2614},{"class":1225,"line":1421},[2615],{"type":19,"tag":1223,"props":2616,"children":2617},{},[2618],{"type":25,"value":2572},{"type":19,"tag":1223,"props":2620,"children":2621},{"class":1225,"line":1430},[2622],{"type":19,"tag":1223,"props":2623,"children":2624},{},[2625],{"type":25,"value":2626},"def isStations():  \n",{"type":19,"tag":1223,"props":2628,"children":2629},{"class":1225,"line":1439},[2630],{"type":19,"tag":1223,"props":2631,"children":2632},{},[2633],{"type":25,"value":2634},"    isStations = os.path.exists('stations.text')           # 判断车站文件是否存在  \n",{"type":19,"tag":1223,"props":2636,"children":2637},{"class":1225,"line":1703},[2638],{"type":19,"tag":1223,"props":2639,"children":2640},{},[2641],{"type":25,"value":2642},"    return isStations\n",{"type":19,"tag":32,"props":2644,"children":2645},{},[2646,2648,2653,2655,2661],{"type":25,"value":2647},"6）打开",{"type":19,"tag":165,"props":2649,"children":2651},{"className":2650},[],[2652],{"type":25,"value":1014},{"type":25,"value":2654},"文件，首先导入",{"type":19,"tag":165,"props":2656,"children":2658},{"className":2657},[],[2659],{"type":25,"value":2660},"get_stations",{"type":25,"value":2662},"文件下的所有方法，然后在模拟python的程序入口处修改代码。接下来判断是否存在所有车站信息的文件，如果没有该文件就下载车站信息的文件然后显示窗体，如果存在将直接显示窗体即可。修改后代码如下：",{"type":19,"tag":1213,"props":2664,"children":2666},{"className":1215,"code":2665,"language":1217,"meta":7,"style":7},"from get_stations import * # 导入get_stations文件下的所有方法\n\nif __name__ == \"__main__\":  \n    if isStations() ==False:     # 判断是否存在所有车站的文件，没有就下载，有就直接显示窗体  \n        getStation()             # 下载所有车站文件  \n        show_MainWindow()        # 调用显示窗体的方法  \n    else:  \n        show_MainWindow()        # 调用显示窗体的方法\n",[2667],{"type":19,"tag":165,"props":2668,"children":2669},{"__ignoreMap":7},[2670,2678,2686,2693,2701,2709,2717,2725],{"type":19,"tag":1223,"props":2671,"children":2672},{"class":1225,"line":1226},[2673],{"type":19,"tag":1223,"props":2674,"children":2675},{},[2676],{"type":25,"value":2677},"from get_stations import * # 导入get_stations文件下的所有方法\n",{"type":19,"tag":1223,"props":2679,"children":2680},{"class":1225,"line":1235},[2681],{"type":19,"tag":1223,"props":2682,"children":2683},{"emptyLinePlaceholder":41},[2684],{"type":25,"value":2685},"\n",{"type":19,"tag":1223,"props":2687,"children":2688},{"class":1225,"line":1244},[2689],{"type":19,"tag":1223,"props":2690,"children":2691},{},[2692],{"type":25,"value":2122},{"type":19,"tag":1223,"props":2694,"children":2695},{"class":1225,"line":1253},[2696],{"type":19,"tag":1223,"props":2697,"children":2698},{},[2699],{"type":25,"value":2700},"    if isStations() ==False:     # 判断是否存在所有车站的文件，没有就下载，有就直接显示窗体  \n",{"type":19,"tag":1223,"props":2702,"children":2703},{"class":1225,"line":1262},[2704],{"type":19,"tag":1223,"props":2705,"children":2706},{},[2707],{"type":25,"value":2708},"        getStation()             # 下载所有车站文件  \n",{"type":19,"tag":1223,"props":2710,"children":2711},{"class":1225,"line":1271},[2712],{"type":19,"tag":1223,"props":2713,"children":2714},{},[2715],{"type":25,"value":2716},"        show_MainWindow()        # 调用显示窗体的方法  \n",{"type":19,"tag":1223,"props":2718,"children":2719},{"class":1225,"line":1385},[2720],{"type":19,"tag":1223,"props":2721,"children":2722},{},[2723],{"type":25,"value":2724},"    else:  \n",{"type":19,"tag":1223,"props":2726,"children":2727},{"class":1225,"line":1394},[2728],{"type":19,"tag":1223,"props":2729,"children":2730},{},[2731],{"type":25,"value":2732},"        show_MainWindow()        # 调用显示窗体的方法\n",{"type":19,"tag":32,"props":2734,"children":2735},{},[2736,2738,2743],{"type":25,"value":2737},"7）在",{"type":19,"tag":165,"props":2739,"children":2741},{"className":2740},[],[2742],{"type":25,"value":1014},{"type":25,"value":2744},"文件下，单击右键菜单中选择“Run 'window'”菜单运行主窗体，主窗体界面显示后在check tickets目录下将自动下载stations.text文件，如图所示，通过该文件可以实现车站名称与对应的英文缩写进行转换。",{"type":19,"tag":32,"props":2746,"children":2747},{},[2748],{"type":19,"tag":50,"props":2749,"children":2752},{"alt":2750,"src":2751},"Pasted image 20250731221559","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731221559.png",[],{"type":19,"tag":20,"props":2754,"children":2756},{"id":2755},"车票信息的请求与显示",[2757],{"type":25,"value":2755},{"type":19,"tag":28,"props":2759,"children":2760},{},[],{"type":19,"tag":135,"props":2762,"children":2764},{"id":2763},"_1-发送与分析车票信息的查询请求",[2765],{"type":25,"value":2766},"1  发送与分析车票信息的查询请求",{"type":19,"tag":32,"props":2768,"children":2769},{},[2770],{"type":25,"value":2771},"得到了获取车票信息的网络请求地址，然后又分析出请求地址的必要参数以及车站名称转换的文件，接下来就需要将主窗体中输入的出发地、目的地以及出发日期三个重要的参数配置到查票的请求地址中，然后分析并接收所查询车票的对应信息。具体步骤如下：",{"type":19,"tag":32,"props":2773,"children":2774},{},[2775],{"type":25,"value":2776},"1）在浏览器中打开如下图所示的查询请求地址。",{"type":19,"tag":32,"props":2778,"children":2779},{},[2780],{"type":19,"tag":50,"props":2781,"children":2784},{"alt":2782,"src":2783},"Pasted image 20250731223116","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731223116.png",[],{"type":19,"tag":32,"props":2786,"children":2787},{},[2788,2790,2796],{"type":25,"value":2789},"然后在浏览器中将以",{"type":19,"tag":165,"props":2791,"children":2793},{"className":2792},[],[2794],{"type":25,"value":2795},"json",{"type":25,"value":2797},"的方式返回车票的查询信息，如图所示。",{"type":19,"tag":32,"props":2799,"children":2800},{},[2801],{"type":19,"tag":50,"props":2802,"children":2805},{"alt":2803,"src":2804},"Pasted image 20250731223611","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731223611.png",[],{"type":19,"tag":917,"props":2807,"children":2808},{},[2809],{"type":19,"tag":32,"props":2810,"children":2811},{},[2812,2814,2820,2822,2827],{"type":25,"value":2813},"说明：在看到的加密信息后先分析数据中是否含有可用的信息，例如，网页中的预订、时间、车次，在上图中的加密信息中含有",{"type":19,"tag":165,"props":2815,"children":2817},{"className":2816},[],[2818],{"type":25,"value":2819},"G13",{"type":25,"value":2821},"的字样和时间信息。然后对照浏览器中余票查询的页面，查找对应车次信息如图所示，此时可以判断返回的",{"type":19,"tag":165,"props":2823,"children":2825},{"className":2824},[],[2826],{"type":25,"value":2795},{"type":25,"value":2828},"信息确实含有可用数据。",{"type":19,"tag":32,"props":2830,"children":2831},{},[2832],{"type":19,"tag":50,"props":2833,"children":2836},{"alt":2834,"src":2835},"Pasted image 20250731223933","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250731223933.png",[],{"type":19,"tag":32,"props":2838,"children":2839},{},[2840,2842,2848,2850,2855,2857,2863,2865,2871],{"type":25,"value":2841},"2）发现可用数据后，在项目中创建",{"type":19,"tag":165,"props":2843,"children":2845},{"className":2844},[],[2846],{"type":25,"value":2847},"query_request.py",{"type":25,"value":2849},"文件，在该文件中首先导入",{"type":19,"tag":165,"props":2851,"children":2853},{"className":2852},[],[2854],{"type":25,"value":2660},{"type":25,"value":2856},"文件下的所有方法，然后分别创建名称为",{"type":19,"tag":165,"props":2858,"children":2860},{"className":2859},[],[2861],{"type":25,"value":2862},"data",{"type":25,"value":2864},"与",{"type":19,"tag":165,"props":2866,"children":2868},{"className":2867},[],[2869],{"type":25,"value":2870},"type_data",{"type":25,"value":2872},"的列表（list）分别用于保存整理好的车次信息与分类后的车次信息。代码如下：",{"type":19,"tag":1213,"props":2874,"children":2876},{"className":1215,"code":2875,"language":1217,"meta":7,"style":7},"import requests  \nimport get_stations  \nfrom fake_useragent import UserAgent        # 导入伪造头部信息模块  \n  \n\"\"\"  \nseat -> 3 车次 6 出发站 7 到达站 8 出发时间 9 到达时间 10 历时 32 商务\u002F特等座 20 优选一等座 31 一等座 30 二等座  21 高级软卧 23 一等卧 28 二等卧 24 软座 29 硬座 26 无座  \n\"\"\"  \n  \ndata = []                                   # 用于保存整理好的车次信息  \ntype_data = []                              # 保存车次分类后最后的数据  \n  \nheaders = {'User-Agent': UserAgent().random,  # 随机生成浏览器头部信息  \n           'Cookie':'_uab_collina=175394...'}\n",[2877],{"type":19,"tag":165,"props":2878,"children":2879},{"__ignoreMap":7},[2880,2888,2896,2904,2911,2919,2927,2934,2941,2949,2957,2964,2972],{"type":19,"tag":1223,"props":2881,"children":2882},{"class":1225,"line":1226},[2883],{"type":19,"tag":1223,"props":2884,"children":2885},{},[2886],{"type":25,"value":2887},"import requests  \n",{"type":19,"tag":1223,"props":2889,"children":2890},{"class":1225,"line":1235},[2891],{"type":19,"tag":1223,"props":2892,"children":2893},{},[2894],{"type":25,"value":2895},"import get_stations  \n",{"type":19,"tag":1223,"props":2897,"children":2898},{"class":1225,"line":1244},[2899],{"type":19,"tag":1223,"props":2900,"children":2901},{},[2902],{"type":25,"value":2903},"from fake_useragent import UserAgent        # 导入伪造头部信息模块  \n",{"type":19,"tag":1223,"props":2905,"children":2906},{"class":1225,"line":1253},[2907],{"type":19,"tag":1223,"props":2908,"children":2909},{},[2910],{"type":25,"value":2572},{"type":19,"tag":1223,"props":2912,"children":2913},{"class":1225,"line":1262},[2914],{"type":19,"tag":1223,"props":2915,"children":2916},{},[2917],{"type":25,"value":2918},"\"\"\"  \n",{"type":19,"tag":1223,"props":2920,"children":2921},{"class":1225,"line":1271},[2922],{"type":19,"tag":1223,"props":2923,"children":2924},{},[2925],{"type":25,"value":2926},"seat -> 3 车次 6 出发站 7 到达站 8 出发时间 9 到达时间 10 历时 32 商务\u002F特等座 20 优选一等座 31 一等座 30 二等座  21 高级软卧 23 一等卧 28 二等卧 24 软座 29 硬座 26 无座  \n",{"type":19,"tag":1223,"props":2928,"children":2929},{"class":1225,"line":1385},[2930],{"type":19,"tag":1223,"props":2931,"children":2932},{},[2933],{"type":25,"value":2918},{"type":19,"tag":1223,"props":2935,"children":2936},{"class":1225,"line":1394},[2937],{"type":19,"tag":1223,"props":2938,"children":2939},{},[2940],{"type":25,"value":2572},{"type":19,"tag":1223,"props":2942,"children":2943},{"class":1225,"line":1403},[2944],{"type":19,"tag":1223,"props":2945,"children":2946},{},[2947],{"type":25,"value":2948},"data = []                                   # 用于保存整理好的车次信息  \n",{"type":19,"tag":1223,"props":2950,"children":2951},{"class":1225,"line":1412},[2952],{"type":19,"tag":1223,"props":2953,"children":2954},{},[2955],{"type":25,"value":2956},"type_data = []                              # 保存车次分类后最后的数据  \n",{"type":19,"tag":1223,"props":2958,"children":2959},{"class":1225,"line":1421},[2960],{"type":19,"tag":1223,"props":2961,"children":2962},{},[2963],{"type":25,"value":2572},{"type":19,"tag":1223,"props":2965,"children":2966},{"class":1225,"line":1430},[2967],{"type":19,"tag":1223,"props":2968,"children":2969},{},[2970],{"type":25,"value":2971},"headers = {'User-Agent': UserAgent().random,  # 随机生成浏览器头部信息  \n",{"type":19,"tag":1223,"props":2973,"children":2974},{"class":1225,"line":1439},[2975],{"type":19,"tag":1223,"props":2976,"children":2977},{},[2978],{"type":25,"value":2979},"           'Cookie':'_uab_collina=175394...'}\n",{"type":19,"tag":917,"props":2981,"children":2982},{},[2983],{"type":19,"tag":32,"props":2984,"children":2985},{},[2986,2988,2991,2993,2999],{"type":25,"value":2987},"说明：由于返回的加密信息很杂乱，所以需要创建“data = ",{"type":19,"tag":1223,"props":2989,"children":2990},{},[],{"type":25,"value":2992},"”列表（list）来保存后期整理好的车次信息，然后需要将车次分类（例如，高铁、动车等），最后创建",{"type":19,"tag":165,"props":2994,"children":2996},{"className":2995},[],[2997],{"type":25,"value":2998},"type_data = []",{"type":25,"value":3000},"列表（list）来保存分类后的车次信息。",{"type":19,"tag":32,"props":3002,"children":3003},{},[3004,3006,3012,3014,3020,3021,3027,3029,3035,3037,3043,3045,3050],{"type":25,"value":3005},"3）创建",{"type":19,"tag":165,"props":3007,"children":3009},{"className":3008},[],[3010],{"type":25,"value":3011},"query()",{"type":25,"value":3013},"方法，在调用该方法时需要三个参数，分别为",{"type":19,"tag":165,"props":3015,"children":3017},{"className":3016},[],[3018],{"type":25,"value":3019},"出发日期",{"type":25,"value":1305},{"type":19,"tag":165,"props":3022,"children":3024},{"className":3023},[],[3025],{"type":25,"value":3026},"出发地",{"type":25,"value":3028},"以及",{"type":19,"tag":165,"props":3030,"children":3032},{"className":3031},[],[3033],{"type":25,"value":3034},"目的地",{"type":25,"value":3036},"；然后创建查询请求的完整地址，并通过",{"type":19,"tag":165,"props":3038,"children":3040},{"className":3039},[],[3041],{"type":25,"value":3042},"format()",{"type":25,"value":3044},"方法格式化地址；再将返回的",{"type":19,"tag":165,"props":3046,"children":3048},{"className":3047},[],[3049],{"type":25,"value":2795},{"type":25,"value":3051},"数据转换为字典类型；最后通过字典类型键值的方法取出对应的数据并进行整理与分类。代码如下：",{"type":19,"tag":1213,"props":3053,"children":3055},{"className":1215,"code":3054,"language":1217,"meta":7,"style":7},"def query(date,from_station, to_station):  \n    data.clear()                               # 清空数据  \n    type_data.clear()                          # 清空车次分类保存的数据  \n    # 查询请求地址  \n    url =   'https:\u002F\u002Fkyfw.12306.cn\u002Fotn\u002FleftTicket\u002FqueryU?leftTicketDTO.train_date={}&leftTicketDTO.from_station={}&leftTicketDTO.to_station={}&purpose_codes=ADULT'.format(date, stat_change(from_station), stat_change(to_station))  \n    # 发送查询请求  \n    response = requests.get(url,headers=headers)  \n    # 将json数据转换为字典类型，通过键值对取数据  \n    result = response.json()  \n    result = result['data']['result']  \n  \n    # 判断车站文件是否存在  \n    if get_stations.isStations():  \n        with open('stations.text','r',encoding='UTF-8') as f:  \n            stations = f.read()  \n        stations = format_file(stations)        # 读取所有车站并转换为dic类型  \n  \n    if  len(result) != 0:                       # 判断返回数据是否为空  \n        for i in result:  \n            # 分割数据并添加到列表中  \n            tmp_list = i.split('|')  \n            global lis_info  \n            t_list = [i for i in tmp_list]  \n            lis_info.append(t_list)  \n            # 因为查询结果中出发站和到达站为站名的缩写字母，所以需要在车站库中找到对应的车站名称  \n            # 根据英文缩写的索引值查找对应的中文名  \n            from_station = list(stations.keys())[list(stations.values()).index(tmp_list[6])]  \n            to_station = list(stations.keys())[list(stations.values()).index(tmp_list[7])]  \n            # 创建座位数组，由于返回的座位数据中含有空既“”，所以将空改成--这样好识别  \n            \"\"\"seat -> 车次 出发站 到达站 出发时间 到达时间 历时 商务\u002F特等座 优选一等座 一等座 二等座  高级软卧 一等卧 二等卧 软座 硬座 无座\"\"\"  \n            seat = [tmp_list[3], from_station, to_station, tmp_list[8], tmp_list[9], tmp_list[10],  \n                    tmp_list[32], tmp_list[20], tmp_list[31], tmp_list[30], tmp_list[21], tmp_list[23],  \n                    tmp_list[28], tmp_list[24], tmp_list[29],  tmp_list[26]]  \n            newSeat = []  \n            # 循环将座位信息中的空既\"\"，改成--这样好识别  \n            for s in seat:  \n                if  s == \"\":  \n                    s = \"{}\".format(\"--\")  \n                else:  \n                    s = \"{}\".format(s)  \n                newSeat.append(s) # 保存新的座位信息  \n            data.append(newSeat)  \n    return  data #  返回整理好的车次信息\n",[3056],{"type":19,"tag":165,"props":3057,"children":3058},{"__ignoreMap":7},[3059,3067,3075,3083,3091,3099,3107,3115,3123,3131,3139,3146,3154,3162,3170,3178,3186,3193,3202,3211,3220,3229,3238,3247,3256,3265,3274,3283,3292,3301,3310,3319,3328,3337,3346,3355,3364,3373,3382,3391,3400,3409,3418],{"type":19,"tag":1223,"props":3060,"children":3061},{"class":1225,"line":1226},[3062],{"type":19,"tag":1223,"props":3063,"children":3064},{},[3065],{"type":25,"value":3066},"def query(date,from_station, to_station):  \n",{"type":19,"tag":1223,"props":3068,"children":3069},{"class":1225,"line":1235},[3070],{"type":19,"tag":1223,"props":3071,"children":3072},{},[3073],{"type":25,"value":3074},"    data.clear()                               # 清空数据  \n",{"type":19,"tag":1223,"props":3076,"children":3077},{"class":1225,"line":1244},[3078],{"type":19,"tag":1223,"props":3079,"children":3080},{},[3081],{"type":25,"value":3082},"    type_data.clear()                          # 清空车次分类保存的数据  \n",{"type":19,"tag":1223,"props":3084,"children":3085},{"class":1225,"line":1253},[3086],{"type":19,"tag":1223,"props":3087,"children":3088},{},[3089],{"type":25,"value":3090},"    # 查询请求地址  \n",{"type":19,"tag":1223,"props":3092,"children":3093},{"class":1225,"line":1262},[3094],{"type":19,"tag":1223,"props":3095,"children":3096},{},[3097],{"type":25,"value":3098},"    url =   'https:\u002F\u002Fkyfw.12306.cn\u002Fotn\u002FleftTicket\u002FqueryU?leftTicketDTO.train_date={}&leftTicketDTO.from_station={}&leftTicketDTO.to_station={}&purpose_codes=ADULT'.format(date, stat_change(from_station), stat_change(to_station))  \n",{"type":19,"tag":1223,"props":3100,"children":3101},{"class":1225,"line":1271},[3102],{"type":19,"tag":1223,"props":3103,"children":3104},{},[3105],{"type":25,"value":3106},"    # 发送查询请求  \n",{"type":19,"tag":1223,"props":3108,"children":3109},{"class":1225,"line":1385},[3110],{"type":19,"tag":1223,"props":3111,"children":3112},{},[3113],{"type":25,"value":3114},"    response = requests.get(url,headers=headers)  \n",{"type":19,"tag":1223,"props":3116,"children":3117},{"class":1225,"line":1394},[3118],{"type":19,"tag":1223,"props":3119,"children":3120},{},[3121],{"type":25,"value":3122},"    # 将json数据转换为字典类型，通过键值对取数据  \n",{"type":19,"tag":1223,"props":3124,"children":3125},{"class":1225,"line":1403},[3126],{"type":19,"tag":1223,"props":3127,"children":3128},{},[3129],{"type":25,"value":3130},"    result = response.json()  \n",{"type":19,"tag":1223,"props":3132,"children":3133},{"class":1225,"line":1412},[3134],{"type":19,"tag":1223,"props":3135,"children":3136},{},[3137],{"type":25,"value":3138},"    result = result['data']['result']  \n",{"type":19,"tag":1223,"props":3140,"children":3141},{"class":1225,"line":1421},[3142],{"type":19,"tag":1223,"props":3143,"children":3144},{},[3145],{"type":25,"value":2572},{"type":19,"tag":1223,"props":3147,"children":3148},{"class":1225,"line":1430},[3149],{"type":19,"tag":1223,"props":3150,"children":3151},{},[3152],{"type":25,"value":3153},"    # 判断车站文件是否存在  \n",{"type":19,"tag":1223,"props":3155,"children":3156},{"class":1225,"line":1439},[3157],{"type":19,"tag":1223,"props":3158,"children":3159},{},[3160],{"type":25,"value":3161},"    if get_stations.isStations():  \n",{"type":19,"tag":1223,"props":3163,"children":3164},{"class":1225,"line":1703},[3165],{"type":19,"tag":1223,"props":3166,"children":3167},{},[3168],{"type":25,"value":3169},"        with open('stations.text','r',encoding='UTF-8') as f:  \n",{"type":19,"tag":1223,"props":3171,"children":3172},{"class":1225,"line":1711},[3173],{"type":19,"tag":1223,"props":3174,"children":3175},{},[3176],{"type":25,"value":3177},"            stations = f.read()  \n",{"type":19,"tag":1223,"props":3179,"children":3180},{"class":1225,"line":1719},[3181],{"type":19,"tag":1223,"props":3182,"children":3183},{},[3184],{"type":25,"value":3185},"        stations = format_file(stations)        # 读取所有车站并转换为dic类型  \n",{"type":19,"tag":1223,"props":3187,"children":3188},{"class":1225,"line":1728},[3189],{"type":19,"tag":1223,"props":3190,"children":3191},{},[3192],{"type":25,"value":2572},{"type":19,"tag":1223,"props":3194,"children":3196},{"class":1225,"line":3195},18,[3197],{"type":19,"tag":1223,"props":3198,"children":3199},{},[3200],{"type":25,"value":3201},"    if  len(result) != 0:                       # 判断返回数据是否为空  \n",{"type":19,"tag":1223,"props":3203,"children":3205},{"class":1225,"line":3204},19,[3206],{"type":19,"tag":1223,"props":3207,"children":3208},{},[3209],{"type":25,"value":3210},"        for i in result:  \n",{"type":19,"tag":1223,"props":3212,"children":3214},{"class":1225,"line":3213},20,[3215],{"type":19,"tag":1223,"props":3216,"children":3217},{},[3218],{"type":25,"value":3219},"            # 分割数据并添加到列表中  \n",{"type":19,"tag":1223,"props":3221,"children":3223},{"class":1225,"line":3222},21,[3224],{"type":19,"tag":1223,"props":3225,"children":3226},{},[3227],{"type":25,"value":3228},"            tmp_list = i.split('|')  \n",{"type":19,"tag":1223,"props":3230,"children":3232},{"class":1225,"line":3231},22,[3233],{"type":19,"tag":1223,"props":3234,"children":3235},{},[3236],{"type":25,"value":3237},"            global lis_info  \n",{"type":19,"tag":1223,"props":3239,"children":3241},{"class":1225,"line":3240},23,[3242],{"type":19,"tag":1223,"props":3243,"children":3244},{},[3245],{"type":25,"value":3246},"            t_list = [i for i in tmp_list]  \n",{"type":19,"tag":1223,"props":3248,"children":3250},{"class":1225,"line":3249},24,[3251],{"type":19,"tag":1223,"props":3252,"children":3253},{},[3254],{"type":25,"value":3255},"            lis_info.append(t_list)  \n",{"type":19,"tag":1223,"props":3257,"children":3259},{"class":1225,"line":3258},25,[3260],{"type":19,"tag":1223,"props":3261,"children":3262},{},[3263],{"type":25,"value":3264},"            # 因为查询结果中出发站和到达站为站名的缩写字母，所以需要在车站库中找到对应的车站名称  \n",{"type":19,"tag":1223,"props":3266,"children":3268},{"class":1225,"line":3267},26,[3269],{"type":19,"tag":1223,"props":3270,"children":3271},{},[3272],{"type":25,"value":3273},"            # 根据英文缩写的索引值查找对应的中文名  \n",{"type":19,"tag":1223,"props":3275,"children":3277},{"class":1225,"line":3276},27,[3278],{"type":19,"tag":1223,"props":3279,"children":3280},{},[3281],{"type":25,"value":3282},"            from_station = list(stations.keys())[list(stations.values()).index(tmp_list[6])]  \n",{"type":19,"tag":1223,"props":3284,"children":3286},{"class":1225,"line":3285},28,[3287],{"type":19,"tag":1223,"props":3288,"children":3289},{},[3290],{"type":25,"value":3291},"            to_station = list(stations.keys())[list(stations.values()).index(tmp_list[7])]  \n",{"type":19,"tag":1223,"props":3293,"children":3295},{"class":1225,"line":3294},29,[3296],{"type":19,"tag":1223,"props":3297,"children":3298},{},[3299],{"type":25,"value":3300},"            # 创建座位数组，由于返回的座位数据中含有空既“”，所以将空改成--这样好识别  \n",{"type":19,"tag":1223,"props":3302,"children":3304},{"class":1225,"line":3303},30,[3305],{"type":19,"tag":1223,"props":3306,"children":3307},{},[3308],{"type":25,"value":3309},"            \"\"\"seat -> 车次 出发站 到达站 出发时间 到达时间 历时 商务\u002F特等座 优选一等座 一等座 二等座  高级软卧 一等卧 二等卧 软座 硬座 无座\"\"\"  \n",{"type":19,"tag":1223,"props":3311,"children":3313},{"class":1225,"line":3312},31,[3314],{"type":19,"tag":1223,"props":3315,"children":3316},{},[3317],{"type":25,"value":3318},"            seat = [tmp_list[3], from_station, to_station, tmp_list[8], tmp_list[9], tmp_list[10],  \n",{"type":19,"tag":1223,"props":3320,"children":3322},{"class":1225,"line":3321},32,[3323],{"type":19,"tag":1223,"props":3324,"children":3325},{},[3326],{"type":25,"value":3327},"                    tmp_list[32], tmp_list[20], tmp_list[31], tmp_list[30], tmp_list[21], tmp_list[23],  \n",{"type":19,"tag":1223,"props":3329,"children":3331},{"class":1225,"line":3330},33,[3332],{"type":19,"tag":1223,"props":3333,"children":3334},{},[3335],{"type":25,"value":3336},"                    tmp_list[28], tmp_list[24], tmp_list[29],  tmp_list[26]]  \n",{"type":19,"tag":1223,"props":3338,"children":3340},{"class":1225,"line":3339},34,[3341],{"type":19,"tag":1223,"props":3342,"children":3343},{},[3344],{"type":25,"value":3345},"            newSeat = []  \n",{"type":19,"tag":1223,"props":3347,"children":3349},{"class":1225,"line":3348},35,[3350],{"type":19,"tag":1223,"props":3351,"children":3352},{},[3353],{"type":25,"value":3354},"            # 循环将座位信息中的空既\"\"，改成--这样好识别  \n",{"type":19,"tag":1223,"props":3356,"children":3358},{"class":1225,"line":3357},36,[3359],{"type":19,"tag":1223,"props":3360,"children":3361},{},[3362],{"type":25,"value":3363},"            for s in seat:  \n",{"type":19,"tag":1223,"props":3365,"children":3367},{"class":1225,"line":3366},37,[3368],{"type":19,"tag":1223,"props":3369,"children":3370},{},[3371],{"type":25,"value":3372},"                if  s == \"\":  \n",{"type":19,"tag":1223,"props":3374,"children":3376},{"class":1225,"line":3375},38,[3377],{"type":19,"tag":1223,"props":3378,"children":3379},{},[3380],{"type":25,"value":3381},"                    s = \"{}\".format(\"--\")  \n",{"type":19,"tag":1223,"props":3383,"children":3385},{"class":1225,"line":3384},39,[3386],{"type":19,"tag":1223,"props":3387,"children":3388},{},[3389],{"type":25,"value":3390},"                else:  \n",{"type":19,"tag":1223,"props":3392,"children":3394},{"class":1225,"line":3393},40,[3395],{"type":19,"tag":1223,"props":3396,"children":3397},{},[3398],{"type":25,"value":3399},"                    s = \"{}\".format(s)  \n",{"type":19,"tag":1223,"props":3401,"children":3403},{"class":1225,"line":3402},41,[3404],{"type":19,"tag":1223,"props":3405,"children":3406},{},[3407],{"type":25,"value":3408},"                newSeat.append(s) # 保存新的座位信息  \n",{"type":19,"tag":1223,"props":3410,"children":3412},{"class":1225,"line":3411},42,[3413],{"type":19,"tag":1223,"props":3414,"children":3415},{},[3416],{"type":25,"value":3417},"            data.append(newSeat)  \n",{"type":19,"tag":1223,"props":3419,"children":3421},{"class":1225,"line":3420},43,[3422],{"type":19,"tag":1223,"props":3423,"children":3424},{},[3425],{"type":25,"value":3426},"    return  data #  返回整理好的车次信息\n",{"type":19,"tag":32,"props":3428,"children":3429},{},[3430],{"type":25,"value":3431},"以下是该函数所调用的其他两个函数体，如下：",{"type":19,"tag":1213,"props":3433,"children":3435},{"className":1215,"code":3434,"language":1217,"meta":7,"style":7},"def stat_change(address):                         # 用来转换请求url中的地址名，将其转换为英文缩写  \n    get_stations.getStation()  \n    address = get_stations.stat.get(address)  \n    return address  \n  \ndef format_file(s : str) -> dict:  \n    dic = {}  \n    lis = s.strip('{').strip('}').split(',')  \n    for i in lis:  \n        i = i.split(':')  \n        dic[eval(i[0])]=eval(i[1])  \n    return dic\n",[3436],{"type":19,"tag":165,"props":3437,"children":3438},{"__ignoreMap":7},[3439,3447,3455,3463,3471,3478,3486,3494,3502,3510,3518,3526],{"type":19,"tag":1223,"props":3440,"children":3441},{"class":1225,"line":1226},[3442],{"type":19,"tag":1223,"props":3443,"children":3444},{},[3445],{"type":25,"value":3446},"def stat_change(address):                         # 用来转换请求url中的地址名，将其转换为英文缩写  \n",{"type":19,"tag":1223,"props":3448,"children":3449},{"class":1225,"line":1235},[3450],{"type":19,"tag":1223,"props":3451,"children":3452},{},[3453],{"type":25,"value":3454},"    get_stations.getStation()  \n",{"type":19,"tag":1223,"props":3456,"children":3457},{"class":1225,"line":1244},[3458],{"type":19,"tag":1223,"props":3459,"children":3460},{},[3461],{"type":25,"value":3462},"    address = get_stations.stat.get(address)  \n",{"type":19,"tag":1223,"props":3464,"children":3465},{"class":1225,"line":1253},[3466],{"type":19,"tag":1223,"props":3467,"children":3468},{},[3469],{"type":25,"value":3470},"    return address  \n",{"type":19,"tag":1223,"props":3472,"children":3473},{"class":1225,"line":1262},[3474],{"type":19,"tag":1223,"props":3475,"children":3476},{},[3477],{"type":25,"value":2572},{"type":19,"tag":1223,"props":3479,"children":3480},{"class":1225,"line":1271},[3481],{"type":19,"tag":1223,"props":3482,"children":3483},{},[3484],{"type":25,"value":3485},"def format_file(s : str) -> dict:  \n",{"type":19,"tag":1223,"props":3487,"children":3488},{"class":1225,"line":1385},[3489],{"type":19,"tag":1223,"props":3490,"children":3491},{},[3492],{"type":25,"value":3493},"    dic = {}  \n",{"type":19,"tag":1223,"props":3495,"children":3496},{"class":1225,"line":1394},[3497],{"type":19,"tag":1223,"props":3498,"children":3499},{},[3500],{"type":25,"value":3501},"    lis = s.strip('{').strip('}').split(',')  \n",{"type":19,"tag":1223,"props":3503,"children":3504},{"class":1225,"line":1403},[3505],{"type":19,"tag":1223,"props":3506,"children":3507},{},[3508],{"type":25,"value":3509},"    for i in lis:  \n",{"type":19,"tag":1223,"props":3511,"children":3512},{"class":1225,"line":1412},[3513],{"type":19,"tag":1223,"props":3514,"children":3515},{},[3516],{"type":25,"value":3517},"        i = i.split(':')  \n",{"type":19,"tag":1223,"props":3519,"children":3520},{"class":1225,"line":1421},[3521],{"type":19,"tag":1223,"props":3522,"children":3523},{},[3524],{"type":25,"value":3525},"        dic[eval(i[0])]=eval(i[1])  \n",{"type":19,"tag":1223,"props":3527,"children":3528},{"class":1225,"line":1430},[3529],{"type":19,"tag":1223,"props":3530,"children":3531},{},[3532],{"type":25,"value":3533},"    return dic\n",{"type":19,"tag":917,"props":3535,"children":3536},{},[3537],{"type":19,"tag":32,"props":3538,"children":3539},{},[3540,3542,3548,3550,3556,3558,3563],{"type":25,"value":3541},"说明：因为返回的",{"type":19,"tag":165,"props":3543,"children":3545},{"className":3544},[],[3546],{"type":25,"value":3547},"Json",{"type":25,"value":3549},"信息顺序比较零乱，所以在获取指定的数据时通过",{"type":19,"tag":165,"props":3551,"children":3553},{"className":3552},[],[3554],{"type":25,"value":3555},"tmp_list",{"type":25,"value":3557},"分割后的列表将数据与浏览器余票查询页面中的数据逐个对比后，才能找出数据所对应的位置。数字为数据分割后",{"type":19,"tag":165,"props":3559,"children":3561},{"className":3560},[],[3562],{"type":25,"value":3555},{"type":25,"value":3564},"的索引值。通过对比后找到的数据位置如下：",{"type":19,"tag":1213,"props":3566,"children":3568},{"className":1215,"code":3567,"language":1217,"meta":7,"style":7},"\"\"\"  \n3 车次 6 出发站 7 到达站 8 出发时间 9 到达时间 10 历时 32 商务\u002F特等座 20 优选一等座 31 一等座 30 二等座  21 高级软卧 23 一等卧 28 二等卧 24 软座 29 硬座 26 无座  \n\"\"\"\n",[3569],{"type":19,"tag":165,"props":3570,"children":3571},{"__ignoreMap":7},[3572,3579,3587],{"type":19,"tag":1223,"props":3573,"children":3574},{"class":1225,"line":1226},[3575],{"type":19,"tag":1223,"props":3576,"children":3577},{},[3578],{"type":25,"value":2918},{"type":19,"tag":1223,"props":3580,"children":3581},{"class":1225,"line":1235},[3582],{"type":19,"tag":1223,"props":3583,"children":3584},{},[3585],{"type":25,"value":3586},"3 车次 6 出发站 7 到达站 8 出发时间 9 到达时间 10 历时 32 商务\u002F特等座 20 优选一等座 31 一等座 30 二等座  21 高级软卧 23 一等卧 28 二等卧 24 软座 29 硬座 26 无座  \n",{"type":19,"tag":1223,"props":3588,"children":3589},{"class":1225,"line":1244},[3590],{"type":19,"tag":1223,"props":3591,"children":3592},{},[3593],{"type":25,"value":3594},"\"\"\"\n",{"type":19,"tag":32,"props":3596,"children":3597},{},[3598],{"type":25,"value":3599},"4）依次创建获取高铁信息、移除高铁信息、获取动车信息、移除动车信息、获取直达信息、移除直达信息、获取特快信息、移除特快信息、获取快速信息及移除快速信息...的方法。这些方法用于车次分类数据的处理，代码如下：",{"type":19,"tag":1213,"props":3601,"children":3603},{"className":1215,"code":3602,"language":1217,"meta":7,"style":7},"# 获取高铁信息的方法  \ndef gc_vehicle():  \n    if len(data) != 0:  \n        for g in data:                   # 循环所有列车数据  \n            if g[0].startswith(\"G\") or g[0].startswith(\"C\"):  # 判断车次首字母是否为高铁  \n                type_data.append(g)  \n# 移除高铁信息的方法  \ndef r_gc_vehicle():  \n    if len(data) != 0 and len(type_data) != 0:  \n        for g in data:  \n            if g[0].startswith(\"G\") or g[0].startswith(\"C\"):  \n                type_data.remove(g)  \n  \n# 获取动车信息的方法  \ndef d_vehicle():  \n    if len(data) != 0:  \n        for d in data:                   # 循环所有列车数据  \n            i = d[0].startswith(\"D\")     # 判断车次首字母是否为动车  \n            if i:                        # 如果是，将该条数据添加到列车数据中  \n                type_data.append(d)  \n# 移除动车信息的方法  \ndef r_d_vehicle():  \n    if len(data) != 0 and len(type_data) != 0:  \n        for d in data:  \n            i = d[0].startswith(\"D\")  \n            if i: type_data.remove(d)  \n  \n# 获取直达信息的方法  \ndef z_vehicle():  \n    if len(data) != 0:  \n        for z in data:                   # 循环所有列车数据  \n            i = z[0].startswith(\"Z\")     # 判断车次首字母是否为直达  \n            if i:                        # 如果是，将该条数据添加到列车数据中  \n                type_data.append(z)  \n# 移除直达信息的方法  \ndef r_z_vehicle():  \n    if len(data) != 0 and len(type_data) != 0:  \n        for z in data:  \n            i = z[0].startswith(\"Z\")  \n            if i: type_data.remove(z)  \n  \n# 获取特快信息的方法  \ndef t_vehicle():  \n    if len(data) != 0:  \n        for t in data:                   # 循环所有列车数据  \n            i = t[0].startswith(\"T\")     # 判断车次首字母是否为特快  \n            if i:                        # 如果是，将该条数据添加到列车数据中  \n                type_data.append(t)  \n# 移除特快信息的方法  \ndef r_t_vehicle():  \n    if len(data) != 0 and len(type_data) != 0:  \n        for t in data:  \n            i = t[0].startswith(\"T\")  \n            if i: type_data.remove(t)  \n  \n# 获取快速列车信息的方法  \ndef k_vehicle():  \n    if len(data) != 0:  \n        for k in data:                   # 循环所有列车数据  \n            i = k[0].startswith(\"K\")     # 判断车次首字母是否为快速列车  \n            if i:                        # 如果是，将该条数据添加到列车数据中  \n                type_data.append(k)  \n# 移除快速列车信息的方法  \ndef r_k_vehicle():  \n    if len(data) != 0 and len(type_data) != 0:  \n        for k in data:  \n            i = k[0].startswith(\"K\")  \n            if i: type_data.remove(k)  \n  \n# 获取复兴号信息的方法  \ndef cr_vehicle():  \n    if len(data) != 0:  \n        for r in data:                   # 循环所有列车数据  \n            i = r[0].startswith(\"CR\")     # 判断车次首字母是否为复兴号  \n            if i:                        # 如果是，将该条数据添加到列车数据中  \n                type_data.append(r)  \n# 移除复兴号信息的方法  \ndef r_cr_vehicle():  \n    if len(data) != 0 and len(type_data) != 0:  \n        for r in data:  \n            i = r[0].startswith(\"CR\")  \n            if i: type_data.remove(r)  \n  \n# 获取智能动车组信息的方法  \ndef crz_vehicle():  \n    if len(data) != 0:  \n        for z in data:                   # 循环所有列车数据  \n            if z[0].startswith(\"CR\") and z[0].endswith(\"Z\"):    # 判断车次首字母是否为智能动车组  \n                type_data.append(z)  \n# 移除智能动车组信息的方法  \ndef r_crz_vehicle():  \n    if len(data) != 0 and len(type_data) != 0:  \n        for z in data:  \n            if z[0].startswith(\"CR\") and z[0].endswith(\"Z\"):  \n                type_data.remove(z)  \n  \n# 获取其他类型信息的方法  \ndef other_vehicle():  \n    if len(data) != 0:  \n        l = ['G','C','T','K','Z','D','CR']  \n        for o in data:  \n            if o[0][0] not in l:              # 判断车次是否为其他类型  \n                type_data.append(o)  \n# 移除其他类型信息的方法  \ndef r_other_vehicle():  \n    if len(data) != 0 and len(type_data) != 0:  \n        l = ['G','C','T','K','Z','D','CR']  \n        for o in data:  \n            if o[0][0] not in l: type_data.remove(o)\n",[3604],{"type":19,"tag":165,"props":3605,"children":3606},{"__ignoreMap":7},[3607,3615,3623,3631,3639,3647,3655,3663,3671,3679,3687,3695,3703,3710,3718,3726,3733,3741,3749,3757,3765,3773,3781,3788,3796,3804,3812,3819,3827,3835,3842,3850,3858,3865,3873,3881,3889,3896,3904,3912,3920,3927,3935,3943,3951,3960,3969,3977,3986,3995,4004,4012,4021,4030,4039,4047,4056,4065,4073,4082,4091,4099,4108,4117,4126,4134,4143,4152,4161,4169,4178,4187,4195,4204,4213,4221,4230,4239,4248,4256,4265,4274,4283,4291,4300,4309,4317,4325,4334,4342,4351,4360,4368,4376,4385,4394,4402,4411,4420,4428,4437,4446,4455,4464,4473,4482,4490,4498,4506],{"type":19,"tag":1223,"props":3608,"children":3609},{"class":1225,"line":1226},[3610],{"type":19,"tag":1223,"props":3611,"children":3612},{},[3613],{"type":25,"value":3614},"# 获取高铁信息的方法  \n",{"type":19,"tag":1223,"props":3616,"children":3617},{"class":1225,"line":1235},[3618],{"type":19,"tag":1223,"props":3619,"children":3620},{},[3621],{"type":25,"value":3622},"def gc_vehicle():  \n",{"type":19,"tag":1223,"props":3624,"children":3625},{"class":1225,"line":1244},[3626],{"type":19,"tag":1223,"props":3627,"children":3628},{},[3629],{"type":25,"value":3630},"    if len(data) != 0:  \n",{"type":19,"tag":1223,"props":3632,"children":3633},{"class":1225,"line":1253},[3634],{"type":19,"tag":1223,"props":3635,"children":3636},{},[3637],{"type":25,"value":3638},"        for g in data:                   # 循环所有列车数据  \n",{"type":19,"tag":1223,"props":3640,"children":3641},{"class":1225,"line":1262},[3642],{"type":19,"tag":1223,"props":3643,"children":3644},{},[3645],{"type":25,"value":3646},"            if g[0].startswith(\"G\") or g[0].startswith(\"C\"):  # 判断车次首字母是否为高铁  \n",{"type":19,"tag":1223,"props":3648,"children":3649},{"class":1225,"line":1271},[3650],{"type":19,"tag":1223,"props":3651,"children":3652},{},[3653],{"type":25,"value":3654},"                type_data.append(g)  \n",{"type":19,"tag":1223,"props":3656,"children":3657},{"class":1225,"line":1385},[3658],{"type":19,"tag":1223,"props":3659,"children":3660},{},[3661],{"type":25,"value":3662},"# 移除高铁信息的方法  \n",{"type":19,"tag":1223,"props":3664,"children":3665},{"class":1225,"line":1394},[3666],{"type":19,"tag":1223,"props":3667,"children":3668},{},[3669],{"type":25,"value":3670},"def r_gc_vehicle():  \n",{"type":19,"tag":1223,"props":3672,"children":3673},{"class":1225,"line":1403},[3674],{"type":19,"tag":1223,"props":3675,"children":3676},{},[3677],{"type":25,"value":3678},"    if len(data) != 0 and len(type_data) != 0:  \n",{"type":19,"tag":1223,"props":3680,"children":3681},{"class":1225,"line":1412},[3682],{"type":19,"tag":1223,"props":3683,"children":3684},{},[3685],{"type":25,"value":3686},"        for g in data:  \n",{"type":19,"tag":1223,"props":3688,"children":3689},{"class":1225,"line":1421},[3690],{"type":19,"tag":1223,"props":3691,"children":3692},{},[3693],{"type":25,"value":3694},"            if g[0].startswith(\"G\") or g[0].startswith(\"C\"):  \n",{"type":19,"tag":1223,"props":3696,"children":3697},{"class":1225,"line":1430},[3698],{"type":19,"tag":1223,"props":3699,"children":3700},{},[3701],{"type":25,"value":3702},"                type_data.remove(g)  \n",{"type":19,"tag":1223,"props":3704,"children":3705},{"class":1225,"line":1439},[3706],{"type":19,"tag":1223,"props":3707,"children":3708},{},[3709],{"type":25,"value":2572},{"type":19,"tag":1223,"props":3711,"children":3712},{"class":1225,"line":1703},[3713],{"type":19,"tag":1223,"props":3714,"children":3715},{},[3716],{"type":25,"value":3717},"# 获取动车信息的方法  \n",{"type":19,"tag":1223,"props":3719,"children":3720},{"class":1225,"line":1711},[3721],{"type":19,"tag":1223,"props":3722,"children":3723},{},[3724],{"type":25,"value":3725},"def d_vehicle():  \n",{"type":19,"tag":1223,"props":3727,"children":3728},{"class":1225,"line":1719},[3729],{"type":19,"tag":1223,"props":3730,"children":3731},{},[3732],{"type":25,"value":3630},{"type":19,"tag":1223,"props":3734,"children":3735},{"class":1225,"line":1728},[3736],{"type":19,"tag":1223,"props":3737,"children":3738},{},[3739],{"type":25,"value":3740},"        for d in data:                   # 循环所有列车数据  \n",{"type":19,"tag":1223,"props":3742,"children":3743},{"class":1225,"line":3195},[3744],{"type":19,"tag":1223,"props":3745,"children":3746},{},[3747],{"type":25,"value":3748},"            i = d[0].startswith(\"D\")     # 判断车次首字母是否为动车  \n",{"type":19,"tag":1223,"props":3750,"children":3751},{"class":1225,"line":3204},[3752],{"type":19,"tag":1223,"props":3753,"children":3754},{},[3755],{"type":25,"value":3756},"            if i:                        # 如果是，将该条数据添加到列车数据中  \n",{"type":19,"tag":1223,"props":3758,"children":3759},{"class":1225,"line":3213},[3760],{"type":19,"tag":1223,"props":3761,"children":3762},{},[3763],{"type":25,"value":3764},"                type_data.append(d)  \n",{"type":19,"tag":1223,"props":3766,"children":3767},{"class":1225,"line":3222},[3768],{"type":19,"tag":1223,"props":3769,"children":3770},{},[3771],{"type":25,"value":3772},"# 移除动车信息的方法  \n",{"type":19,"tag":1223,"props":3774,"children":3775},{"class":1225,"line":3231},[3776],{"type":19,"tag":1223,"props":3777,"children":3778},{},[3779],{"type":25,"value":3780},"def r_d_vehicle():  \n",{"type":19,"tag":1223,"props":3782,"children":3783},{"class":1225,"line":3240},[3784],{"type":19,"tag":1223,"props":3785,"children":3786},{},[3787],{"type":25,"value":3678},{"type":19,"tag":1223,"props":3789,"children":3790},{"class":1225,"line":3249},[3791],{"type":19,"tag":1223,"props":3792,"children":3793},{},[3794],{"type":25,"value":3795},"        for d in data:  \n",{"type":19,"tag":1223,"props":3797,"children":3798},{"class":1225,"line":3258},[3799],{"type":19,"tag":1223,"props":3800,"children":3801},{},[3802],{"type":25,"value":3803},"            i = d[0].startswith(\"D\")  \n",{"type":19,"tag":1223,"props":3805,"children":3806},{"class":1225,"line":3267},[3807],{"type":19,"tag":1223,"props":3808,"children":3809},{},[3810],{"type":25,"value":3811},"            if i: type_data.remove(d)  \n",{"type":19,"tag":1223,"props":3813,"children":3814},{"class":1225,"line":3276},[3815],{"type":19,"tag":1223,"props":3816,"children":3817},{},[3818],{"type":25,"value":2572},{"type":19,"tag":1223,"props":3820,"children":3821},{"class":1225,"line":3285},[3822],{"type":19,"tag":1223,"props":3823,"children":3824},{},[3825],{"type":25,"value":3826},"# 获取直达信息的方法  \n",{"type":19,"tag":1223,"props":3828,"children":3829},{"class":1225,"line":3294},[3830],{"type":19,"tag":1223,"props":3831,"children":3832},{},[3833],{"type":25,"value":3834},"def z_vehicle():  \n",{"type":19,"tag":1223,"props":3836,"children":3837},{"class":1225,"line":3303},[3838],{"type":19,"tag":1223,"props":3839,"children":3840},{},[3841],{"type":25,"value":3630},{"type":19,"tag":1223,"props":3843,"children":3844},{"class":1225,"line":3312},[3845],{"type":19,"tag":1223,"props":3846,"children":3847},{},[3848],{"type":25,"value":3849},"        for z in data:                   # 循环所有列车数据  \n",{"type":19,"tag":1223,"props":3851,"children":3852},{"class":1225,"line":3321},[3853],{"type":19,"tag":1223,"props":3854,"children":3855},{},[3856],{"type":25,"value":3857},"            i = z[0].startswith(\"Z\")     # 判断车次首字母是否为直达  \n",{"type":19,"tag":1223,"props":3859,"children":3860},{"class":1225,"line":3330},[3861],{"type":19,"tag":1223,"props":3862,"children":3863},{},[3864],{"type":25,"value":3756},{"type":19,"tag":1223,"props":3866,"children":3867},{"class":1225,"line":3339},[3868],{"type":19,"tag":1223,"props":3869,"children":3870},{},[3871],{"type":25,"value":3872},"                type_data.append(z)  \n",{"type":19,"tag":1223,"props":3874,"children":3875},{"class":1225,"line":3348},[3876],{"type":19,"tag":1223,"props":3877,"children":3878},{},[3879],{"type":25,"value":3880},"# 移除直达信息的方法  \n",{"type":19,"tag":1223,"props":3882,"children":3883},{"class":1225,"line":3357},[3884],{"type":19,"tag":1223,"props":3885,"children":3886},{},[3887],{"type":25,"value":3888},"def r_z_vehicle():  \n",{"type":19,"tag":1223,"props":3890,"children":3891},{"class":1225,"line":3366},[3892],{"type":19,"tag":1223,"props":3893,"children":3894},{},[3895],{"type":25,"value":3678},{"type":19,"tag":1223,"props":3897,"children":3898},{"class":1225,"line":3375},[3899],{"type":19,"tag":1223,"props":3900,"children":3901},{},[3902],{"type":25,"value":3903},"        for z in data:  \n",{"type":19,"tag":1223,"props":3905,"children":3906},{"class":1225,"line":3384},[3907],{"type":19,"tag":1223,"props":3908,"children":3909},{},[3910],{"type":25,"value":3911},"            i = z[0].startswith(\"Z\")  \n",{"type":19,"tag":1223,"props":3913,"children":3914},{"class":1225,"line":3393},[3915],{"type":19,"tag":1223,"props":3916,"children":3917},{},[3918],{"type":25,"value":3919},"            if i: type_data.remove(z)  \n",{"type":19,"tag":1223,"props":3921,"children":3922},{"class":1225,"line":3402},[3923],{"type":19,"tag":1223,"props":3924,"children":3925},{},[3926],{"type":25,"value":2572},{"type":19,"tag":1223,"props":3928,"children":3929},{"class":1225,"line":3411},[3930],{"type":19,"tag":1223,"props":3931,"children":3932},{},[3933],{"type":25,"value":3934},"# 获取特快信息的方法  \n",{"type":19,"tag":1223,"props":3936,"children":3937},{"class":1225,"line":3420},[3938],{"type":19,"tag":1223,"props":3939,"children":3940},{},[3941],{"type":25,"value":3942},"def t_vehicle():  \n",{"type":19,"tag":1223,"props":3944,"children":3946},{"class":1225,"line":3945},44,[3947],{"type":19,"tag":1223,"props":3948,"children":3949},{},[3950],{"type":25,"value":3630},{"type":19,"tag":1223,"props":3952,"children":3954},{"class":1225,"line":3953},45,[3955],{"type":19,"tag":1223,"props":3956,"children":3957},{},[3958],{"type":25,"value":3959},"        for t in data:                   # 循环所有列车数据  \n",{"type":19,"tag":1223,"props":3961,"children":3963},{"class":1225,"line":3962},46,[3964],{"type":19,"tag":1223,"props":3965,"children":3966},{},[3967],{"type":25,"value":3968},"            i = t[0].startswith(\"T\")     # 判断车次首字母是否为特快  \n",{"type":19,"tag":1223,"props":3970,"children":3972},{"class":1225,"line":3971},47,[3973],{"type":19,"tag":1223,"props":3974,"children":3975},{},[3976],{"type":25,"value":3756},{"type":19,"tag":1223,"props":3978,"children":3980},{"class":1225,"line":3979},48,[3981],{"type":19,"tag":1223,"props":3982,"children":3983},{},[3984],{"type":25,"value":3985},"                type_data.append(t)  \n",{"type":19,"tag":1223,"props":3987,"children":3989},{"class":1225,"line":3988},49,[3990],{"type":19,"tag":1223,"props":3991,"children":3992},{},[3993],{"type":25,"value":3994},"# 移除特快信息的方法  \n",{"type":19,"tag":1223,"props":3996,"children":3998},{"class":1225,"line":3997},50,[3999],{"type":19,"tag":1223,"props":4000,"children":4001},{},[4002],{"type":25,"value":4003},"def r_t_vehicle():  \n",{"type":19,"tag":1223,"props":4005,"children":4007},{"class":1225,"line":4006},51,[4008],{"type":19,"tag":1223,"props":4009,"children":4010},{},[4011],{"type":25,"value":3678},{"type":19,"tag":1223,"props":4013,"children":4015},{"class":1225,"line":4014},52,[4016],{"type":19,"tag":1223,"props":4017,"children":4018},{},[4019],{"type":25,"value":4020},"        for t in data:  \n",{"type":19,"tag":1223,"props":4022,"children":4024},{"class":1225,"line":4023},53,[4025],{"type":19,"tag":1223,"props":4026,"children":4027},{},[4028],{"type":25,"value":4029},"            i = t[0].startswith(\"T\")  \n",{"type":19,"tag":1223,"props":4031,"children":4033},{"class":1225,"line":4032},54,[4034],{"type":19,"tag":1223,"props":4035,"children":4036},{},[4037],{"type":25,"value":4038},"            if i: type_data.remove(t)  \n",{"type":19,"tag":1223,"props":4040,"children":4042},{"class":1225,"line":4041},55,[4043],{"type":19,"tag":1223,"props":4044,"children":4045},{},[4046],{"type":25,"value":2572},{"type":19,"tag":1223,"props":4048,"children":4050},{"class":1225,"line":4049},56,[4051],{"type":19,"tag":1223,"props":4052,"children":4053},{},[4054],{"type":25,"value":4055},"# 获取快速列车信息的方法  \n",{"type":19,"tag":1223,"props":4057,"children":4059},{"class":1225,"line":4058},57,[4060],{"type":19,"tag":1223,"props":4061,"children":4062},{},[4063],{"type":25,"value":4064},"def k_vehicle():  \n",{"type":19,"tag":1223,"props":4066,"children":4068},{"class":1225,"line":4067},58,[4069],{"type":19,"tag":1223,"props":4070,"children":4071},{},[4072],{"type":25,"value":3630},{"type":19,"tag":1223,"props":4074,"children":4076},{"class":1225,"line":4075},59,[4077],{"type":19,"tag":1223,"props":4078,"children":4079},{},[4080],{"type":25,"value":4081},"        for k in data:                   # 循环所有列车数据  \n",{"type":19,"tag":1223,"props":4083,"children":4085},{"class":1225,"line":4084},60,[4086],{"type":19,"tag":1223,"props":4087,"children":4088},{},[4089],{"type":25,"value":4090},"            i = k[0].startswith(\"K\")     # 判断车次首字母是否为快速列车  \n",{"type":19,"tag":1223,"props":4092,"children":4094},{"class":1225,"line":4093},61,[4095],{"type":19,"tag":1223,"props":4096,"children":4097},{},[4098],{"type":25,"value":3756},{"type":19,"tag":1223,"props":4100,"children":4102},{"class":1225,"line":4101},62,[4103],{"type":19,"tag":1223,"props":4104,"children":4105},{},[4106],{"type":25,"value":4107},"                type_data.append(k)  \n",{"type":19,"tag":1223,"props":4109,"children":4111},{"class":1225,"line":4110},63,[4112],{"type":19,"tag":1223,"props":4113,"children":4114},{},[4115],{"type":25,"value":4116},"# 移除快速列车信息的方法  \n",{"type":19,"tag":1223,"props":4118,"children":4120},{"class":1225,"line":4119},64,[4121],{"type":19,"tag":1223,"props":4122,"children":4123},{},[4124],{"type":25,"value":4125},"def r_k_vehicle():  \n",{"type":19,"tag":1223,"props":4127,"children":4129},{"class":1225,"line":4128},65,[4130],{"type":19,"tag":1223,"props":4131,"children":4132},{},[4133],{"type":25,"value":3678},{"type":19,"tag":1223,"props":4135,"children":4137},{"class":1225,"line":4136},66,[4138],{"type":19,"tag":1223,"props":4139,"children":4140},{},[4141],{"type":25,"value":4142},"        for k in data:  \n",{"type":19,"tag":1223,"props":4144,"children":4146},{"class":1225,"line":4145},67,[4147],{"type":19,"tag":1223,"props":4148,"children":4149},{},[4150],{"type":25,"value":4151},"            i = k[0].startswith(\"K\")  \n",{"type":19,"tag":1223,"props":4153,"children":4155},{"class":1225,"line":4154},68,[4156],{"type":19,"tag":1223,"props":4157,"children":4158},{},[4159],{"type":25,"value":4160},"            if i: type_data.remove(k)  \n",{"type":19,"tag":1223,"props":4162,"children":4164},{"class":1225,"line":4163},69,[4165],{"type":19,"tag":1223,"props":4166,"children":4167},{},[4168],{"type":25,"value":2572},{"type":19,"tag":1223,"props":4170,"children":4172},{"class":1225,"line":4171},70,[4173],{"type":19,"tag":1223,"props":4174,"children":4175},{},[4176],{"type":25,"value":4177},"# 获取复兴号信息的方法  \n",{"type":19,"tag":1223,"props":4179,"children":4181},{"class":1225,"line":4180},71,[4182],{"type":19,"tag":1223,"props":4183,"children":4184},{},[4185],{"type":25,"value":4186},"def cr_vehicle():  \n",{"type":19,"tag":1223,"props":4188,"children":4190},{"class":1225,"line":4189},72,[4191],{"type":19,"tag":1223,"props":4192,"children":4193},{},[4194],{"type":25,"value":3630},{"type":19,"tag":1223,"props":4196,"children":4198},{"class":1225,"line":4197},73,[4199],{"type":19,"tag":1223,"props":4200,"children":4201},{},[4202],{"type":25,"value":4203},"        for r in data:                   # 循环所有列车数据  \n",{"type":19,"tag":1223,"props":4205,"children":4207},{"class":1225,"line":4206},74,[4208],{"type":19,"tag":1223,"props":4209,"children":4210},{},[4211],{"type":25,"value":4212},"            i = r[0].startswith(\"CR\")     # 判断车次首字母是否为复兴号  \n",{"type":19,"tag":1223,"props":4214,"children":4216},{"class":1225,"line":4215},75,[4217],{"type":19,"tag":1223,"props":4218,"children":4219},{},[4220],{"type":25,"value":3756},{"type":19,"tag":1223,"props":4222,"children":4224},{"class":1225,"line":4223},76,[4225],{"type":19,"tag":1223,"props":4226,"children":4227},{},[4228],{"type":25,"value":4229},"                type_data.append(r)  \n",{"type":19,"tag":1223,"props":4231,"children":4233},{"class":1225,"line":4232},77,[4234],{"type":19,"tag":1223,"props":4235,"children":4236},{},[4237],{"type":25,"value":4238},"# 移除复兴号信息的方法  \n",{"type":19,"tag":1223,"props":4240,"children":4242},{"class":1225,"line":4241},78,[4243],{"type":19,"tag":1223,"props":4244,"children":4245},{},[4246],{"type":25,"value":4247},"def r_cr_vehicle():  \n",{"type":19,"tag":1223,"props":4249,"children":4251},{"class":1225,"line":4250},79,[4252],{"type":19,"tag":1223,"props":4253,"children":4254},{},[4255],{"type":25,"value":3678},{"type":19,"tag":1223,"props":4257,"children":4259},{"class":1225,"line":4258},80,[4260],{"type":19,"tag":1223,"props":4261,"children":4262},{},[4263],{"type":25,"value":4264},"        for r in data:  \n",{"type":19,"tag":1223,"props":4266,"children":4268},{"class":1225,"line":4267},81,[4269],{"type":19,"tag":1223,"props":4270,"children":4271},{},[4272],{"type":25,"value":4273},"            i = r[0].startswith(\"CR\")  \n",{"type":19,"tag":1223,"props":4275,"children":4277},{"class":1225,"line":4276},82,[4278],{"type":19,"tag":1223,"props":4279,"children":4280},{},[4281],{"type":25,"value":4282},"            if i: type_data.remove(r)  \n",{"type":19,"tag":1223,"props":4284,"children":4286},{"class":1225,"line":4285},83,[4287],{"type":19,"tag":1223,"props":4288,"children":4289},{},[4290],{"type":25,"value":2572},{"type":19,"tag":1223,"props":4292,"children":4294},{"class":1225,"line":4293},84,[4295],{"type":19,"tag":1223,"props":4296,"children":4297},{},[4298],{"type":25,"value":4299},"# 获取智能动车组信息的方法  \n",{"type":19,"tag":1223,"props":4301,"children":4303},{"class":1225,"line":4302},85,[4304],{"type":19,"tag":1223,"props":4305,"children":4306},{},[4307],{"type":25,"value":4308},"def crz_vehicle():  \n",{"type":19,"tag":1223,"props":4310,"children":4312},{"class":1225,"line":4311},86,[4313],{"type":19,"tag":1223,"props":4314,"children":4315},{},[4316],{"type":25,"value":3630},{"type":19,"tag":1223,"props":4318,"children":4320},{"class":1225,"line":4319},87,[4321],{"type":19,"tag":1223,"props":4322,"children":4323},{},[4324],{"type":25,"value":3849},{"type":19,"tag":1223,"props":4326,"children":4328},{"class":1225,"line":4327},88,[4329],{"type":19,"tag":1223,"props":4330,"children":4331},{},[4332],{"type":25,"value":4333},"            if z[0].startswith(\"CR\") and z[0].endswith(\"Z\"):    # 判断车次首字母是否为智能动车组  \n",{"type":19,"tag":1223,"props":4335,"children":4337},{"class":1225,"line":4336},89,[4338],{"type":19,"tag":1223,"props":4339,"children":4340},{},[4341],{"type":25,"value":3872},{"type":19,"tag":1223,"props":4343,"children":4345},{"class":1225,"line":4344},90,[4346],{"type":19,"tag":1223,"props":4347,"children":4348},{},[4349],{"type":25,"value":4350},"# 移除智能动车组信息的方法  \n",{"type":19,"tag":1223,"props":4352,"children":4354},{"class":1225,"line":4353},91,[4355],{"type":19,"tag":1223,"props":4356,"children":4357},{},[4358],{"type":25,"value":4359},"def r_crz_vehicle():  \n",{"type":19,"tag":1223,"props":4361,"children":4363},{"class":1225,"line":4362},92,[4364],{"type":19,"tag":1223,"props":4365,"children":4366},{},[4367],{"type":25,"value":3678},{"type":19,"tag":1223,"props":4369,"children":4371},{"class":1225,"line":4370},93,[4372],{"type":19,"tag":1223,"props":4373,"children":4374},{},[4375],{"type":25,"value":3903},{"type":19,"tag":1223,"props":4377,"children":4379},{"class":1225,"line":4378},94,[4380],{"type":19,"tag":1223,"props":4381,"children":4382},{},[4383],{"type":25,"value":4384},"            if z[0].startswith(\"CR\") and z[0].endswith(\"Z\"):  \n",{"type":19,"tag":1223,"props":4386,"children":4388},{"class":1225,"line":4387},95,[4389],{"type":19,"tag":1223,"props":4390,"children":4391},{},[4392],{"type":25,"value":4393},"                type_data.remove(z)  \n",{"type":19,"tag":1223,"props":4395,"children":4397},{"class":1225,"line":4396},96,[4398],{"type":19,"tag":1223,"props":4399,"children":4400},{},[4401],{"type":25,"value":2572},{"type":19,"tag":1223,"props":4403,"children":4405},{"class":1225,"line":4404},97,[4406],{"type":19,"tag":1223,"props":4407,"children":4408},{},[4409],{"type":25,"value":4410},"# 获取其他类型信息的方法  \n",{"type":19,"tag":1223,"props":4412,"children":4414},{"class":1225,"line":4413},98,[4415],{"type":19,"tag":1223,"props":4416,"children":4417},{},[4418],{"type":25,"value":4419},"def other_vehicle():  \n",{"type":19,"tag":1223,"props":4421,"children":4423},{"class":1225,"line":4422},99,[4424],{"type":19,"tag":1223,"props":4425,"children":4426},{},[4427],{"type":25,"value":3630},{"type":19,"tag":1223,"props":4429,"children":4431},{"class":1225,"line":4430},100,[4432],{"type":19,"tag":1223,"props":4433,"children":4434},{},[4435],{"type":25,"value":4436},"        l = ['G','C','T','K','Z','D','CR']  \n",{"type":19,"tag":1223,"props":4438,"children":4440},{"class":1225,"line":4439},101,[4441],{"type":19,"tag":1223,"props":4442,"children":4443},{},[4444],{"type":25,"value":4445},"        for o in data:  \n",{"type":19,"tag":1223,"props":4447,"children":4449},{"class":1225,"line":4448},102,[4450],{"type":19,"tag":1223,"props":4451,"children":4452},{},[4453],{"type":25,"value":4454},"            if o[0][0] not in l:              # 判断车次是否为其他类型  \n",{"type":19,"tag":1223,"props":4456,"children":4458},{"class":1225,"line":4457},103,[4459],{"type":19,"tag":1223,"props":4460,"children":4461},{},[4462],{"type":25,"value":4463},"                type_data.append(o)  \n",{"type":19,"tag":1223,"props":4465,"children":4467},{"class":1225,"line":4466},104,[4468],{"type":19,"tag":1223,"props":4469,"children":4470},{},[4471],{"type":25,"value":4472},"# 移除其他类型信息的方法  \n",{"type":19,"tag":1223,"props":4474,"children":4476},{"class":1225,"line":4475},105,[4477],{"type":19,"tag":1223,"props":4478,"children":4479},{},[4480],{"type":25,"value":4481},"def r_other_vehicle():  \n",{"type":19,"tag":1223,"props":4483,"children":4485},{"class":1225,"line":4484},106,[4486],{"type":19,"tag":1223,"props":4487,"children":4488},{},[4489],{"type":25,"value":3678},{"type":19,"tag":1223,"props":4491,"children":4493},{"class":1225,"line":4492},107,[4494],{"type":19,"tag":1223,"props":4495,"children":4496},{},[4497],{"type":25,"value":4436},{"type":19,"tag":1223,"props":4499,"children":4501},{"class":1225,"line":4500},108,[4502],{"type":19,"tag":1223,"props":4503,"children":4504},{},[4505],{"type":25,"value":4445},{"type":19,"tag":1223,"props":4507,"children":4509},{"class":1225,"line":4508},109,[4510],{"type":19,"tag":1223,"props":4511,"children":4512},{},[4513],{"type":25,"value":4514},"            if o[0][0] not in l: type_data.remove(o)\n",{"type":19,"tag":135,"props":4516,"children":4518},{"id":4517},"_2在主窗体中显示查票信息",[4519],{"type":25,"value":4520},"2  在主窗体中显示查票信息",{"type":19,"tag":32,"props":4522,"children":4523},{},[4524],{"type":25,"value":4525},"完成了车票信息查询请求的文件后，接下来需要将获取的车票信息显示在快手爬票的主窗体当中。具体实现步骤如下：",{"type":19,"tag":32,"props":4527,"children":4528},{},[4529,4530,4535,4537,4543,4545,4551,4553,4558,4560,4566],{"type":25,"value":1196},{"type":19,"tag":165,"props":4531,"children":4533},{"className":4532},[],[4534],{"type":25,"value":1014},{"type":25,"value":4536},"文件，导入",{"type":19,"tag":165,"props":4538,"children":4540},{"className":4539},[],[4541],{"type":25,"value":4542},"PyQt5.QtCore",{"type":25,"value":4544},"模块中的Qt类，然后导入",{"type":19,"tag":165,"props":4546,"children":4548},{"className":4547},[],[4549],{"type":25,"value":4550},"PyQt5.QtWidgets",{"type":25,"value":4552},"模块与",{"type":19,"tag":165,"props":4554,"children":4556},{"className":4555},[],[4557],{"type":25,"value":1295},{"type":25,"value":4559},"模块下的所有方法，再导入",{"type":19,"tag":165,"props":4561,"children":4563},{"className":4562},[],[4564],{"type":25,"value":4565},"query_request",{"type":25,"value":4567},"文件中的所有方法。代码如下：",{"type":19,"tag":1213,"props":4569,"children":4571},{"className":1215,"code":4570,"language":1217,"meta":7,"style":7},"from PyQt5.QtGui import *  \nfrom PyQt5.QtCore import Qt  \nfrom PyQt5.QtWidgets import *  \nfrom query_request import *\n",[4572],{"type":19,"tag":165,"props":4573,"children":4574},{"__ignoreMap":7},[4575,4583,4591,4599],{"type":19,"tag":1223,"props":4576,"children":4577},{"class":1225,"line":1226},[4578],{"type":19,"tag":1223,"props":4579,"children":4580},{},[4581],{"type":25,"value":4582},"from PyQt5.QtGui import *  \n",{"type":19,"tag":1223,"props":4584,"children":4585},{"class":1225,"line":1235},[4586],{"type":19,"tag":1223,"props":4587,"children":4588},{},[4589],{"type":25,"value":4590},"from PyQt5.QtCore import Qt  \n",{"type":19,"tag":1223,"props":4592,"children":4593},{"class":1225,"line":1244},[4594],{"type":19,"tag":1223,"props":4595,"children":4596},{},[4597],{"type":25,"value":4598},"from PyQt5.QtWidgets import *  \n",{"type":19,"tag":1223,"props":4600,"children":4601},{"class":1225,"line":1253},[4602],{"type":19,"tag":1223,"props":4603,"children":4604},{},[4605],{"type":25,"value":4606},"from query_request import *\n",{"type":19,"tag":32,"props":4608,"children":4609},{},[4610,4612,4617,4619,4624],{"type":25,"value":4611},"2）在",{"type":19,"tag":165,"props":4613,"children":4615},{"className":4614},[],[4616],{"type":25,"value":1209},{"type":25,"value":4618},"方法中找到用于显示车票信息的",{"type":19,"tag":165,"props":4620,"children":4622},{"className":4621},[],[4623],{"type":25,"value":330},{"type":25,"value":4625},"表格控件。然后为该控件设置相关属性，关键代码如下：",{"type":19,"tag":1213,"props":4627,"children":4629},{"className":1215,"code":4628,"language":1217,"meta":7,"style":7},"self.tableView = QtWidgets.QTableView(self.centralwidget)  \nself.tableView.setGeometry(QtCore.QRect(0, 340, 1131, 431))  \nself.tableView.setObjectName(\"tableView\")  \nself.model = QStandardItemModel()  # 创建存储数据的模式  \n# 根据空间自动改变列宽度并不可修改列宽度  \nself.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)  \n# 设置表头不见  \nself.tableView.horizontalHeader().setVisible(False)  \n# 纵向表头不可见  \nself.tableView.verticalHeader().setVisible(False)  \n# 设置表格内容文字大小  \nfont = QtGui.QFont()  \nfont.setPointSize(10)  \nself.tableView.setFont(font)  \n# 设置表格内容不可编辑  \nself.tableView.setEditTriggers(QAbstractItemView.NoEditTriggers)  \n# 垂直滚动条始终开启  \nself.tableView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)\n",[4630],{"type":19,"tag":165,"props":4631,"children":4632},{"__ignoreMap":7},[4633,4641,4649,4657,4665,4673,4681,4689,4697,4705,4713,4721,4729,4737,4745,4753,4761,4769],{"type":19,"tag":1223,"props":4634,"children":4635},{"class":1225,"line":1226},[4636],{"type":19,"tag":1223,"props":4637,"children":4638},{},[4639],{"type":25,"value":4640},"self.tableView = QtWidgets.QTableView(self.centralwidget)  \n",{"type":19,"tag":1223,"props":4642,"children":4643},{"class":1225,"line":1235},[4644],{"type":19,"tag":1223,"props":4645,"children":4646},{},[4647],{"type":25,"value":4648},"self.tableView.setGeometry(QtCore.QRect(0, 340, 1131, 431))  \n",{"type":19,"tag":1223,"props":4650,"children":4651},{"class":1225,"line":1244},[4652],{"type":19,"tag":1223,"props":4653,"children":4654},{},[4655],{"type":25,"value":4656},"self.tableView.setObjectName(\"tableView\")  \n",{"type":19,"tag":1223,"props":4658,"children":4659},{"class":1225,"line":1253},[4660],{"type":19,"tag":1223,"props":4661,"children":4662},{},[4663],{"type":25,"value":4664},"self.model = QStandardItemModel()  # 创建存储数据的模式  \n",{"type":19,"tag":1223,"props":4666,"children":4667},{"class":1225,"line":1262},[4668],{"type":19,"tag":1223,"props":4669,"children":4670},{},[4671],{"type":25,"value":4672},"# 根据空间自动改变列宽度并不可修改列宽度  \n",{"type":19,"tag":1223,"props":4674,"children":4675},{"class":1225,"line":1271},[4676],{"type":19,"tag":1223,"props":4677,"children":4678},{},[4679],{"type":25,"value":4680},"self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)  \n",{"type":19,"tag":1223,"props":4682,"children":4683},{"class":1225,"line":1385},[4684],{"type":19,"tag":1223,"props":4685,"children":4686},{},[4687],{"type":25,"value":4688},"# 设置表头不见  \n",{"type":19,"tag":1223,"props":4690,"children":4691},{"class":1225,"line":1394},[4692],{"type":19,"tag":1223,"props":4693,"children":4694},{},[4695],{"type":25,"value":4696},"self.tableView.horizontalHeader().setVisible(False)  \n",{"type":19,"tag":1223,"props":4698,"children":4699},{"class":1225,"line":1403},[4700],{"type":19,"tag":1223,"props":4701,"children":4702},{},[4703],{"type":25,"value":4704},"# 纵向表头不可见  \n",{"type":19,"tag":1223,"props":4706,"children":4707},{"class":1225,"line":1412},[4708],{"type":19,"tag":1223,"props":4709,"children":4710},{},[4711],{"type":25,"value":4712},"self.tableView.verticalHeader().setVisible(False)  \n",{"type":19,"tag":1223,"props":4714,"children":4715},{"class":1225,"line":1421},[4716],{"type":19,"tag":1223,"props":4717,"children":4718},{},[4719],{"type":25,"value":4720},"# 设置表格内容文字大小  \n",{"type":19,"tag":1223,"props":4722,"children":4723},{"class":1225,"line":1430},[4724],{"type":19,"tag":1223,"props":4725,"children":4726},{},[4727],{"type":25,"value":4728},"font = QtGui.QFont()  \n",{"type":19,"tag":1223,"props":4730,"children":4731},{"class":1225,"line":1439},[4732],{"type":19,"tag":1223,"props":4733,"children":4734},{},[4735],{"type":25,"value":4736},"font.setPointSize(10)  \n",{"type":19,"tag":1223,"props":4738,"children":4739},{"class":1225,"line":1703},[4740],{"type":19,"tag":1223,"props":4741,"children":4742},{},[4743],{"type":25,"value":4744},"self.tableView.setFont(font)  \n",{"type":19,"tag":1223,"props":4746,"children":4747},{"class":1225,"line":1711},[4748],{"type":19,"tag":1223,"props":4749,"children":4750},{},[4751],{"type":25,"value":4752},"# 设置表格内容不可编辑  \n",{"type":19,"tag":1223,"props":4754,"children":4755},{"class":1225,"line":1719},[4756],{"type":19,"tag":1223,"props":4757,"children":4758},{},[4759],{"type":25,"value":4760},"self.tableView.setEditTriggers(QAbstractItemView.NoEditTriggers)  \n",{"type":19,"tag":1223,"props":4762,"children":4763},{"class":1225,"line":1728},[4764],{"type":19,"tag":1223,"props":4765,"children":4766},{},[4767],{"type":25,"value":4768},"# 垂直滚动条始终开启  \n",{"type":19,"tag":1223,"props":4770,"children":4771},{"class":1225,"line":3195},[4772],{"type":19,"tag":1223,"props":4773,"children":4774},{},[4775],{"type":25,"value":4776},"self.tableView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)\n",{"type":19,"tag":32,"props":4778,"children":4779},{},[4780],{"type":25,"value":4781},"3）导入time模块，该模块提供了用于处理时间的各种方法。然后在代码块的最外层创建get_time()方法用于获取系统的当前日期，再创建is_valid_date()方法用于判断输入的日期是否是一个有效的日期字符串，代码如下：",{"type":19,"tag":1213,"props":4783,"children":4785},{"className":1215,"code":4784,"language":1217,"meta":7,"style":7},"import time\ndef get_time():  \n    # 获取当前时间的时间戳  \n    now = int(time.time())  \n    # 转换为其他日期格式，如：%Y-%m-%d %H:%M:%S  \n    timeStruct = time.localtime(now)  \n    str_Time = time.strftime(\"%Y-%m-%d %H:%M:%S\", timeStruct)  \n    return str_Time  \n  \ndef is_valid_date(str_Time):  \n    \"\"\"判断是否是一个有效的日期字符串\"\"\"  \n    try:  \n        time.strptime(str_Time, \"%Y-%m-%d\")  \n        return True  \n    except:  \n        return False\n",[4786],{"type":19,"tag":165,"props":4787,"children":4788},{"__ignoreMap":7},[4789,4797,4805,4813,4821,4829,4837,4845,4853,4860,4868,4876,4884,4892,4900,4908],{"type":19,"tag":1223,"props":4790,"children":4791},{"class":1225,"line":1226},[4792],{"type":19,"tag":1223,"props":4793,"children":4794},{},[4795],{"type":25,"value":4796},"import time\n",{"type":19,"tag":1223,"props":4798,"children":4799},{"class":1225,"line":1235},[4800],{"type":19,"tag":1223,"props":4801,"children":4802},{},[4803],{"type":25,"value":4804},"def get_time():  \n",{"type":19,"tag":1223,"props":4806,"children":4807},{"class":1225,"line":1244},[4808],{"type":19,"tag":1223,"props":4809,"children":4810},{},[4811],{"type":25,"value":4812},"    # 获取当前时间的时间戳  \n",{"type":19,"tag":1223,"props":4814,"children":4815},{"class":1225,"line":1253},[4816],{"type":19,"tag":1223,"props":4817,"children":4818},{},[4819],{"type":25,"value":4820},"    now = int(time.time())  \n",{"type":19,"tag":1223,"props":4822,"children":4823},{"class":1225,"line":1262},[4824],{"type":19,"tag":1223,"props":4825,"children":4826},{},[4827],{"type":25,"value":4828},"    # 转换为其他日期格式，如：%Y-%m-%d %H:%M:%S  \n",{"type":19,"tag":1223,"props":4830,"children":4831},{"class":1225,"line":1271},[4832],{"type":19,"tag":1223,"props":4833,"children":4834},{},[4835],{"type":25,"value":4836},"    timeStruct = time.localtime(now)  \n",{"type":19,"tag":1223,"props":4838,"children":4839},{"class":1225,"line":1385},[4840],{"type":19,"tag":1223,"props":4841,"children":4842},{},[4843],{"type":25,"value":4844},"    str_Time = time.strftime(\"%Y-%m-%d %H:%M:%S\", timeStruct)  \n",{"type":19,"tag":1223,"props":4846,"children":4847},{"class":1225,"line":1394},[4848],{"type":19,"tag":1223,"props":4849,"children":4850},{},[4851],{"type":25,"value":4852},"    return str_Time  \n",{"type":19,"tag":1223,"props":4854,"children":4855},{"class":1225,"line":1403},[4856],{"type":19,"tag":1223,"props":4857,"children":4858},{},[4859],{"type":25,"value":2572},{"type":19,"tag":1223,"props":4861,"children":4862},{"class":1225,"line":1412},[4863],{"type":19,"tag":1223,"props":4864,"children":4865},{},[4866],{"type":25,"value":4867},"def is_valid_date(str_Time):  \n",{"type":19,"tag":1223,"props":4869,"children":4870},{"class":1225,"line":1421},[4871],{"type":19,"tag":1223,"props":4872,"children":4873},{},[4874],{"type":25,"value":4875},"    \"\"\"判断是否是一个有效的日期字符串\"\"\"  \n",{"type":19,"tag":1223,"props":4877,"children":4878},{"class":1225,"line":1430},[4879],{"type":19,"tag":1223,"props":4880,"children":4881},{},[4882],{"type":25,"value":4883},"    try:  \n",{"type":19,"tag":1223,"props":4885,"children":4886},{"class":1225,"line":1439},[4887],{"type":19,"tag":1223,"props":4888,"children":4889},{},[4890],{"type":25,"value":4891},"        time.strptime(str_Time, \"%Y-%m-%d\")  \n",{"type":19,"tag":1223,"props":4893,"children":4894},{"class":1225,"line":1703},[4895],{"type":19,"tag":1223,"props":4896,"children":4897},{},[4898],{"type":25,"value":4899},"        return True  \n",{"type":19,"tag":1223,"props":4901,"children":4902},{"class":1225,"line":1711},[4903],{"type":19,"tag":1223,"props":4904,"children":4905},{},[4906],{"type":25,"value":4907},"    except:  \n",{"type":19,"tag":1223,"props":4909,"children":4910},{"class":1225,"line":1719},[4911],{"type":19,"tag":1223,"props":4912,"children":4913},{},[4914],{"type":25,"value":4915},"        return False\n",{"type":19,"tag":32,"props":4917,"children":4918},{},[4919,4921,4927,4928,4934,4935,4941,4942,4948,4949,4955,4956,4962,4963,4969,4970,4976],{"type":25,"value":4920},"4）依次创建",{"type":19,"tag":165,"props":4922,"children":4924},{"className":4923},[],[4925],{"type":25,"value":4926},"change_G()",{"type":25,"value":1305},{"type":19,"tag":165,"props":4929,"children":4931},{"className":4930},[],[4932],{"type":25,"value":4933},"change_D()",{"type":25,"value":1305},{"type":19,"tag":165,"props":4936,"children":4938},{"className":4937},[],[4939],{"type":25,"value":4940},"change_Z()",{"type":25,"value":1305},{"type":19,"tag":165,"props":4943,"children":4945},{"className":4944},[],[4946],{"type":25,"value":4947},"change_T()",{"type":25,"value":1305},{"type":19,"tag":165,"props":4950,"children":4952},{"className":4951},[],[4953],{"type":25,"value":4954},"change_K()",{"type":25,"value":1305},{"type":19,"tag":165,"props":4957,"children":4959},{"className":4958},[],[4960],{"type":25,"value":4961},"change_CR()",{"type":25,"value":1305},{"type":19,"tag":165,"props":4964,"children":4966},{"className":4965},[],[4967],{"type":25,"value":4968},"change_CRZ()",{"type":25,"value":1305},{"type":19,"tag":165,"props":4971,"children":4973},{"className":4972},[],[4974],{"type":25,"value":4975},"change_Other()",{"type":25,"value":4977},"方法，以上方法均为车次分类复选框的事件处理，由于代码几乎相同，此处提供关键代码如下：",{"type":19,"tag":1213,"props":4979,"children":4981},{"className":1215,"code":4980,"language":1217,"meta":7,"style":7},"# 高铁复选框事件处理  \ndef change_G(self,state):  \n    # 选中将高铁信息添加到最后要显示的数据当中  \n    if state == QtCore.Qt.Checked:  \n        # 获取高铁信息  \n        query(\"2025-08-10\",\"天水南\",\"西安北\")# 测试数据  \n        gc_vehicle()  \n        # 通过表格显示该车型数据  \n        self.displayTable(len(type_data),16,type_data)  \n    else:  \n        # 取消选中状态将移除该数据  \n        r_gc_vehicle()  \n        self.displayTable(len(type_data),16,type_data)\n",[4982],{"type":19,"tag":165,"props":4983,"children":4984},{"__ignoreMap":7},[4985,4993,5001,5009,5017,5025,5033,5041,5049,5057,5064,5072,5080],{"type":19,"tag":1223,"props":4986,"children":4987},{"class":1225,"line":1226},[4988],{"type":19,"tag":1223,"props":4989,"children":4990},{},[4991],{"type":25,"value":4992},"# 高铁复选框事件处理  \n",{"type":19,"tag":1223,"props":4994,"children":4995},{"class":1225,"line":1235},[4996],{"type":19,"tag":1223,"props":4997,"children":4998},{},[4999],{"type":25,"value":5000},"def change_G(self,state):  \n",{"type":19,"tag":1223,"props":5002,"children":5003},{"class":1225,"line":1244},[5004],{"type":19,"tag":1223,"props":5005,"children":5006},{},[5007],{"type":25,"value":5008},"    # 选中将高铁信息添加到最后要显示的数据当中  \n",{"type":19,"tag":1223,"props":5010,"children":5011},{"class":1225,"line":1253},[5012],{"type":19,"tag":1223,"props":5013,"children":5014},{},[5015],{"type":25,"value":5016},"    if state == QtCore.Qt.Checked:  \n",{"type":19,"tag":1223,"props":5018,"children":5019},{"class":1225,"line":1262},[5020],{"type":19,"tag":1223,"props":5021,"children":5022},{},[5023],{"type":25,"value":5024},"        # 获取高铁信息  \n",{"type":19,"tag":1223,"props":5026,"children":5027},{"class":1225,"line":1271},[5028],{"type":19,"tag":1223,"props":5029,"children":5030},{},[5031],{"type":25,"value":5032},"        query(\"2025-08-10\",\"天水南\",\"西安北\")# 测试数据  \n",{"type":19,"tag":1223,"props":5034,"children":5035},{"class":1225,"line":1385},[5036],{"type":19,"tag":1223,"props":5037,"children":5038},{},[5039],{"type":25,"value":5040},"        gc_vehicle()  \n",{"type":19,"tag":1223,"props":5042,"children":5043},{"class":1225,"line":1394},[5044],{"type":19,"tag":1223,"props":5045,"children":5046},{},[5047],{"type":25,"value":5048},"        # 通过表格显示该车型数据  \n",{"type":19,"tag":1223,"props":5050,"children":5051},{"class":1225,"line":1403},[5052],{"type":19,"tag":1223,"props":5053,"children":5054},{},[5055],{"type":25,"value":5056},"        self.displayTable(len(type_data),16,type_data)  \n",{"type":19,"tag":1223,"props":5058,"children":5059},{"class":1225,"line":1412},[5060],{"type":19,"tag":1223,"props":5061,"children":5062},{},[5063],{"type":25,"value":2724},{"type":19,"tag":1223,"props":5065,"children":5066},{"class":1225,"line":1421},[5067],{"type":19,"tag":1223,"props":5068,"children":5069},{},[5070],{"type":25,"value":5071},"        # 取消选中状态将移除该数据  \n",{"type":19,"tag":1223,"props":5073,"children":5074},{"class":1225,"line":1430},[5075],{"type":19,"tag":1223,"props":5076,"children":5077},{},[5078],{"type":25,"value":5079},"        r_gc_vehicle()  \n",{"type":19,"tag":1223,"props":5081,"children":5082},{"class":1225,"line":1439},[5083],{"type":19,"tag":1223,"props":5084,"children":5085},{},[5086],{"type":25,"value":5087},"        self.displayTable(len(type_data),16,type_data)\n",{"type":19,"tag":32,"props":5089,"children":5090},{},[5091,5093,5099],{"type":25,"value":5092},"5）创建",{"type":19,"tag":165,"props":5094,"children":5096},{"className":5095},[],[5097],{"type":25,"value":5098},"change_All()",{"type":25,"value":5100},"方法，该方法用于将所有车次分类复选框勾选处理方法，代码如下：",{"type":19,"tag":1213,"props":5102,"children":5104},{"className":1215,"code":5103,"language":1217,"meta":7,"style":7},"def change_ALL(self,state):  \n    if state == QtCore.Qt.Checked:  \n        self.checkBox_G.setChecked(True)  \n        self.checkBox_D.setChecked(True)  \n        self.checkBox_Z.setChecked(True)  \n        self.checkBox_EMU.setChecked(True)  \n        self.checkBox_T.setChecked(True)  \n        self.checkBox_K.setChecked(True)  \n        self.checkBox_O.setChecked(True)  \n        self.checkBox_F.setChecked(True)  \n    else:  \n        self.checkBox_G.setChecked(False)  \n        self.checkBox_D.setChecked(False)  \n        self.checkBox_Z.setChecked(False)  \n        self.checkBox_EMU.setChecked(False)  \n        self.checkBox_T.setChecked(False)  \n        self.checkBox_K.setChecked(False)  \n        self.checkBox_O.setChecked(False)  \n        self.checkBox_F.setChecked(False)\n",[5105],{"type":19,"tag":165,"props":5106,"children":5107},{"__ignoreMap":7},[5108,5116,5123,5131,5139,5147,5155,5163,5171,5179,5187,5194,5202,5210,5218,5226,5234,5242,5250],{"type":19,"tag":1223,"props":5109,"children":5110},{"class":1225,"line":1226},[5111],{"type":19,"tag":1223,"props":5112,"children":5113},{},[5114],{"type":25,"value":5115},"def change_ALL(self,state):  \n",{"type":19,"tag":1223,"props":5117,"children":5118},{"class":1225,"line":1235},[5119],{"type":19,"tag":1223,"props":5120,"children":5121},{},[5122],{"type":25,"value":5016},{"type":19,"tag":1223,"props":5124,"children":5125},{"class":1225,"line":1244},[5126],{"type":19,"tag":1223,"props":5127,"children":5128},{},[5129],{"type":25,"value":5130},"        self.checkBox_G.setChecked(True)  \n",{"type":19,"tag":1223,"props":5132,"children":5133},{"class":1225,"line":1253},[5134],{"type":19,"tag":1223,"props":5135,"children":5136},{},[5137],{"type":25,"value":5138},"        self.checkBox_D.setChecked(True)  \n",{"type":19,"tag":1223,"props":5140,"children":5141},{"class":1225,"line":1262},[5142],{"type":19,"tag":1223,"props":5143,"children":5144},{},[5145],{"type":25,"value":5146},"        self.checkBox_Z.setChecked(True)  \n",{"type":19,"tag":1223,"props":5148,"children":5149},{"class":1225,"line":1271},[5150],{"type":19,"tag":1223,"props":5151,"children":5152},{},[5153],{"type":25,"value":5154},"        self.checkBox_EMU.setChecked(True)  \n",{"type":19,"tag":1223,"props":5156,"children":5157},{"class":1225,"line":1385},[5158],{"type":19,"tag":1223,"props":5159,"children":5160},{},[5161],{"type":25,"value":5162},"        self.checkBox_T.setChecked(True)  \n",{"type":19,"tag":1223,"props":5164,"children":5165},{"class":1225,"line":1394},[5166],{"type":19,"tag":1223,"props":5167,"children":5168},{},[5169],{"type":25,"value":5170},"        self.checkBox_K.setChecked(True)  \n",{"type":19,"tag":1223,"props":5172,"children":5173},{"class":1225,"line":1403},[5174],{"type":19,"tag":1223,"props":5175,"children":5176},{},[5177],{"type":25,"value":5178},"        self.checkBox_O.setChecked(True)  \n",{"type":19,"tag":1223,"props":5180,"children":5181},{"class":1225,"line":1412},[5182],{"type":19,"tag":1223,"props":5183,"children":5184},{},[5185],{"type":25,"value":5186},"        self.checkBox_F.setChecked(True)  \n",{"type":19,"tag":1223,"props":5188,"children":5189},{"class":1225,"line":1421},[5190],{"type":19,"tag":1223,"props":5191,"children":5192},{},[5193],{"type":25,"value":2724},{"type":19,"tag":1223,"props":5195,"children":5196},{"class":1225,"line":1430},[5197],{"type":19,"tag":1223,"props":5198,"children":5199},{},[5200],{"type":25,"value":5201},"        self.checkBox_G.setChecked(False)  \n",{"type":19,"tag":1223,"props":5203,"children":5204},{"class":1225,"line":1439},[5205],{"type":19,"tag":1223,"props":5206,"children":5207},{},[5208],{"type":25,"value":5209},"        self.checkBox_D.setChecked(False)  \n",{"type":19,"tag":1223,"props":5211,"children":5212},{"class":1225,"line":1703},[5213],{"type":19,"tag":1223,"props":5214,"children":5215},{},[5216],{"type":25,"value":5217},"        self.checkBox_Z.setChecked(False)  \n",{"type":19,"tag":1223,"props":5219,"children":5220},{"class":1225,"line":1711},[5221],{"type":19,"tag":1223,"props":5222,"children":5223},{},[5224],{"type":25,"value":5225},"        self.checkBox_EMU.setChecked(False)  \n",{"type":19,"tag":1223,"props":5227,"children":5228},{"class":1225,"line":1719},[5229],{"type":19,"tag":1223,"props":5230,"children":5231},{},[5232],{"type":25,"value":5233},"        self.checkBox_T.setChecked(False)  \n",{"type":19,"tag":1223,"props":5235,"children":5236},{"class":1225,"line":1728},[5237],{"type":19,"tag":1223,"props":5238,"children":5239},{},[5240],{"type":25,"value":5241},"        self.checkBox_K.setChecked(False)  \n",{"type":19,"tag":1223,"props":5243,"children":5244},{"class":1225,"line":3195},[5245],{"type":19,"tag":1223,"props":5246,"children":5247},{},[5248],{"type":25,"value":5249},"        self.checkBox_O.setChecked(False)  \n",{"type":19,"tag":1223,"props":5251,"children":5252},{"class":1225,"line":3204},[5253],{"type":19,"tag":1223,"props":5254,"children":5255},{},[5256],{"type":25,"value":5257},"        self.checkBox_F.setChecked(False)\n",{"type":19,"tag":32,"props":5259,"children":5260},{},[5261,5263,5269,5271,5277],{"type":25,"value":5262},"6）创建",{"type":19,"tag":165,"props":5264,"children":5266},{"className":5265},[],[5267],{"type":25,"value":5268},"messageDialog()",{"type":25,"value":5270},"方法，用于显示主窗体非法操作的消息提示框；创建",{"type":19,"tag":165,"props":5272,"children":5274},{"className":5273},[],[5275],{"type":25,"value":5276},"displayTable()",{"type":25,"value":5278},"方法，用于显示车次信息的表格与内容。代码如下：",{"type":19,"tag":1213,"props":5280,"children":5282},{"className":1215,"code":5281,"language":1217,"meta":7,"style":7},"# 异常提示框  \ndef messageDialog(self, title, message):  \n    msg = QMessageBox(QMessageBox.Warning, title, message)  \n    msg.exec_()  \n  \n# 更新表单  \ndef displayTable(self, row_count, col_count, data):  \n    self.model.setRowCount(row_count)  # 设置行数  \n    self.model.setColumnCount(col_count)  # 设置列数  \n    for row in range(row_count):  \n        for col in range(col_count):  \n            item = QStandardItem(str(data[row][col]))  # data是二维列表  \n            self.model.setItem(row, col, item)  \n    self.tableView.setModel(self.model)  # 重新绑定模型（确保刷新）\n",[5283],{"type":19,"tag":165,"props":5284,"children":5285},{"__ignoreMap":7},[5286,5294,5302,5310,5318,5325,5333,5341,5349,5357,5365,5373,5381,5389],{"type":19,"tag":1223,"props":5287,"children":5288},{"class":1225,"line":1226},[5289],{"type":19,"tag":1223,"props":5290,"children":5291},{},[5292],{"type":25,"value":5293},"# 异常提示框  \n",{"type":19,"tag":1223,"props":5295,"children":5296},{"class":1225,"line":1235},[5297],{"type":19,"tag":1223,"props":5298,"children":5299},{},[5300],{"type":25,"value":5301},"def messageDialog(self, title, message):  \n",{"type":19,"tag":1223,"props":5303,"children":5304},{"class":1225,"line":1244},[5305],{"type":19,"tag":1223,"props":5306,"children":5307},{},[5308],{"type":25,"value":5309},"    msg = QMessageBox(QMessageBox.Warning, title, message)  \n",{"type":19,"tag":1223,"props":5311,"children":5312},{"class":1225,"line":1253},[5313],{"type":19,"tag":1223,"props":5314,"children":5315},{},[5316],{"type":25,"value":5317},"    msg.exec_()  \n",{"type":19,"tag":1223,"props":5319,"children":5320},{"class":1225,"line":1262},[5321],{"type":19,"tag":1223,"props":5322,"children":5323},{},[5324],{"type":25,"value":2572},{"type":19,"tag":1223,"props":5326,"children":5327},{"class":1225,"line":1271},[5328],{"type":19,"tag":1223,"props":5329,"children":5330},{},[5331],{"type":25,"value":5332},"# 更新表单  \n",{"type":19,"tag":1223,"props":5334,"children":5335},{"class":1225,"line":1385},[5336],{"type":19,"tag":1223,"props":5337,"children":5338},{},[5339],{"type":25,"value":5340},"def displayTable(self, row_count, col_count, data):  \n",{"type":19,"tag":1223,"props":5342,"children":5343},{"class":1225,"line":1394},[5344],{"type":19,"tag":1223,"props":5345,"children":5346},{},[5347],{"type":25,"value":5348},"    self.model.setRowCount(row_count)  # 设置行数  \n",{"type":19,"tag":1223,"props":5350,"children":5351},{"class":1225,"line":1403},[5352],{"type":19,"tag":1223,"props":5353,"children":5354},{},[5355],{"type":25,"value":5356},"    self.model.setColumnCount(col_count)  # 设置列数  \n",{"type":19,"tag":1223,"props":5358,"children":5359},{"class":1225,"line":1412},[5360],{"type":19,"tag":1223,"props":5361,"children":5362},{},[5363],{"type":25,"value":5364},"    for row in range(row_count):  \n",{"type":19,"tag":1223,"props":5366,"children":5367},{"class":1225,"line":1421},[5368],{"type":19,"tag":1223,"props":5369,"children":5370},{},[5371],{"type":25,"value":5372},"        for col in range(col_count):  \n",{"type":19,"tag":1223,"props":5374,"children":5375},{"class":1225,"line":1430},[5376],{"type":19,"tag":1223,"props":5377,"children":5378},{},[5379],{"type":25,"value":5380},"            item = QStandardItem(str(data[row][col]))  # data是二维列表  \n",{"type":19,"tag":1223,"props":5382,"children":5383},{"class":1225,"line":1439},[5384],{"type":19,"tag":1223,"props":5385,"children":5386},{},[5387],{"type":25,"value":5388},"            self.model.setItem(row, col, item)  \n",{"type":19,"tag":1223,"props":5390,"children":5391},{"class":1225,"line":1703},[5392],{"type":19,"tag":1223,"props":5393,"children":5394},{},[5395],{"type":25,"value":5396},"    self.tableView.setModel(self.model)  # 重新绑定模型（确保刷新）\n",{"type":19,"tag":32,"props":5398,"children":5399},{},[5400,5402,5408,5410,5415],{"type":25,"value":5401},"7）创建",{"type":19,"tag":165,"props":5403,"children":5405},{"className":5404},[],[5406],{"type":25,"value":5407},"on_click()",{"type":25,"value":5409},"方法，该方法是查询按钮的单击事件。在该方法中首先获取出发地、目的地与出发日期三个编辑框的输入内容，然后对三个编辑框中输入的内容进行合法检测，符合规范后调用query()方法提交车票查询的请求并且将返回的数据赋值给data，最后通过调用",{"type":19,"tag":165,"props":5411,"children":5413},{"className":5412},[],[5414],{"type":25,"value":5276},{"type":25,"value":5416},"方法实现在表格中显示车票查询的全部信息。代码如下：",{"type":19,"tag":1213,"props":5418,"children":5420},{"className":1215,"code":5419,"language":1217,"meta":7,"style":7},"# 查询按钮的单击事件  \n  \ndef on_click(self):  \n  \n    get_from = self.textEdit.toPlainText()  # 获取出发地  \n    get_to = self.textEdit_2.toPlainText()  # 获取到达地  \n    get_date = self.textEdit_3.toPlainText()  # 获取出发时间  \n    # 判断车站文件是否存在  \n    if isStations() == True:  \n        stations = give_dic()  # 读取所有车站并转换为dic类型  \n        # 判断所有参数是否为空，以及出发地、目的地、出发日期  \n        if get_from != \"\" and get_to != \"\" and get_date != \"\":  \n            # 判断输入的车站名称是否存在，以及时间格式是否正确  \n            if get_from in stations and get_to in stations and is_valid_date(get_date):  \n                # 获取输入的日期是当前年初到现在一共过了多少天  \n                inputYearDay = time.strptime(get_date, \"%Y-%m-%d\").tm_yday  \n                # 获取系统当前日期是当前年初到现在一共过了多少天  \n                yearToday = time.localtime(time.time()).tm_yday  \n                # 计算时间差，也就是输入的日期减掉系统当前的日期  \n                timeDifference = inputYearDay - yearToday  \n                # 判断时间差为0时证明是查询当前的查票  \n                # 以及29天以后的车票，12306官方要求只能查询30天以内的车票  \n                if timeDifference >= 0 and timeDifference \u003C= 28:  \n                    # 在所有车站文件中找到对应的参数  \n                    from_station = stations[get_from]  # 出发地  \n                    to_station = stations[get_to]  # 目的地  \n                    # 发送查询请求，并获取返回的信息  \n                    data = query(get_date, from_station, to_station)  \n                    self.checkBox_default()  # 调用取消勾选所有车次分类复选框  \n                    if len(data) != 0:  # 判断返回的数据是否为空  \n                        # 如果不是空的数据就将车票信息显示在表格中  \n                        self.displayTable(len(data), 16, data)  \n                    else:  \n                        self.messageDialog('警告', '没有返回的网络数据！')  \n                else:  \n                    self.messageDialog('警告','超出查询日期的范围内,不可查询昨天的车票信息,以及29天以后的车票信息！')  \n            else:  \n                self.messageDialog('警告', '输入的站名不存在,或日期格式不正确！')  \n        else:  \n            self.messageDialog('警告', '请填写车站名称！')  \n    else:  \n        self.messageDialog('警告', '未下载车站查询文件！')\n",[5421],{"type":19,"tag":165,"props":5422,"children":5423},{"__ignoreMap":7},[5424,5432,5439,5447,5454,5462,5470,5478,5485,5493,5501,5509,5517,5525,5533,5541,5549,5557,5565,5573,5581,5589,5597,5605,5613,5621,5629,5637,5645,5653,5661,5669,5677,5685,5693,5700,5708,5716,5724,5732,5740,5747],{"type":19,"tag":1223,"props":5425,"children":5426},{"class":1225,"line":1226},[5427],{"type":19,"tag":1223,"props":5428,"children":5429},{},[5430],{"type":25,"value":5431},"# 查询按钮的单击事件  \n",{"type":19,"tag":1223,"props":5433,"children":5434},{"class":1225,"line":1235},[5435],{"type":19,"tag":1223,"props":5436,"children":5437},{},[5438],{"type":25,"value":2572},{"type":19,"tag":1223,"props":5440,"children":5441},{"class":1225,"line":1244},[5442],{"type":19,"tag":1223,"props":5443,"children":5444},{},[5445],{"type":25,"value":5446},"def on_click(self):  \n",{"type":19,"tag":1223,"props":5448,"children":5449},{"class":1225,"line":1253},[5450],{"type":19,"tag":1223,"props":5451,"children":5452},{},[5453],{"type":25,"value":2572},{"type":19,"tag":1223,"props":5455,"children":5456},{"class":1225,"line":1262},[5457],{"type":19,"tag":1223,"props":5458,"children":5459},{},[5460],{"type":25,"value":5461},"    get_from = self.textEdit.toPlainText()  # 获取出发地  \n",{"type":19,"tag":1223,"props":5463,"children":5464},{"class":1225,"line":1271},[5465],{"type":19,"tag":1223,"props":5466,"children":5467},{},[5468],{"type":25,"value":5469},"    get_to = self.textEdit_2.toPlainText()  # 获取到达地  \n",{"type":19,"tag":1223,"props":5471,"children":5472},{"class":1225,"line":1385},[5473],{"type":19,"tag":1223,"props":5474,"children":5475},{},[5476],{"type":25,"value":5477},"    get_date = self.textEdit_3.toPlainText()  # 获取出发时间  \n",{"type":19,"tag":1223,"props":5479,"children":5480},{"class":1225,"line":1394},[5481],{"type":19,"tag":1223,"props":5482,"children":5483},{},[5484],{"type":25,"value":3153},{"type":19,"tag":1223,"props":5486,"children":5487},{"class":1225,"line":1403},[5488],{"type":19,"tag":1223,"props":5489,"children":5490},{},[5491],{"type":25,"value":5492},"    if isStations() == True:  \n",{"type":19,"tag":1223,"props":5494,"children":5495},{"class":1225,"line":1412},[5496],{"type":19,"tag":1223,"props":5497,"children":5498},{},[5499],{"type":25,"value":5500},"        stations = give_dic()  # 读取所有车站并转换为dic类型  \n",{"type":19,"tag":1223,"props":5502,"children":5503},{"class":1225,"line":1421},[5504],{"type":19,"tag":1223,"props":5505,"children":5506},{},[5507],{"type":25,"value":5508},"        # 判断所有参数是否为空，以及出发地、目的地、出发日期  \n",{"type":19,"tag":1223,"props":5510,"children":5511},{"class":1225,"line":1430},[5512],{"type":19,"tag":1223,"props":5513,"children":5514},{},[5515],{"type":25,"value":5516},"        if get_from != \"\" and get_to != \"\" and get_date != \"\":  \n",{"type":19,"tag":1223,"props":5518,"children":5519},{"class":1225,"line":1439},[5520],{"type":19,"tag":1223,"props":5521,"children":5522},{},[5523],{"type":25,"value":5524},"            # 判断输入的车站名称是否存在，以及时间格式是否正确  \n",{"type":19,"tag":1223,"props":5526,"children":5527},{"class":1225,"line":1703},[5528],{"type":19,"tag":1223,"props":5529,"children":5530},{},[5531],{"type":25,"value":5532},"            if get_from in stations and get_to in stations and is_valid_date(get_date):  \n",{"type":19,"tag":1223,"props":5534,"children":5535},{"class":1225,"line":1711},[5536],{"type":19,"tag":1223,"props":5537,"children":5538},{},[5539],{"type":25,"value":5540},"                # 获取输入的日期是当前年初到现在一共过了多少天  \n",{"type":19,"tag":1223,"props":5542,"children":5543},{"class":1225,"line":1719},[5544],{"type":19,"tag":1223,"props":5545,"children":5546},{},[5547],{"type":25,"value":5548},"                inputYearDay = time.strptime(get_date, \"%Y-%m-%d\").tm_yday  \n",{"type":19,"tag":1223,"props":5550,"children":5551},{"class":1225,"line":1728},[5552],{"type":19,"tag":1223,"props":5553,"children":5554},{},[5555],{"type":25,"value":5556},"                # 获取系统当前日期是当前年初到现在一共过了多少天  \n",{"type":19,"tag":1223,"props":5558,"children":5559},{"class":1225,"line":3195},[5560],{"type":19,"tag":1223,"props":5561,"children":5562},{},[5563],{"type":25,"value":5564},"                yearToday = time.localtime(time.time()).tm_yday  \n",{"type":19,"tag":1223,"props":5566,"children":5567},{"class":1225,"line":3204},[5568],{"type":19,"tag":1223,"props":5569,"children":5570},{},[5571],{"type":25,"value":5572},"                # 计算时间差，也就是输入的日期减掉系统当前的日期  \n",{"type":19,"tag":1223,"props":5574,"children":5575},{"class":1225,"line":3213},[5576],{"type":19,"tag":1223,"props":5577,"children":5578},{},[5579],{"type":25,"value":5580},"                timeDifference = inputYearDay - yearToday  \n",{"type":19,"tag":1223,"props":5582,"children":5583},{"class":1225,"line":3222},[5584],{"type":19,"tag":1223,"props":5585,"children":5586},{},[5587],{"type":25,"value":5588},"                # 判断时间差为0时证明是查询当前的查票  \n",{"type":19,"tag":1223,"props":5590,"children":5591},{"class":1225,"line":3231},[5592],{"type":19,"tag":1223,"props":5593,"children":5594},{},[5595],{"type":25,"value":5596},"                # 以及29天以后的车票，12306官方要求只能查询30天以内的车票  \n",{"type":19,"tag":1223,"props":5598,"children":5599},{"class":1225,"line":3240},[5600],{"type":19,"tag":1223,"props":5601,"children":5602},{},[5603],{"type":25,"value":5604},"                if timeDifference >= 0 and timeDifference \u003C= 28:  \n",{"type":19,"tag":1223,"props":5606,"children":5607},{"class":1225,"line":3249},[5608],{"type":19,"tag":1223,"props":5609,"children":5610},{},[5611],{"type":25,"value":5612},"                    # 在所有车站文件中找到对应的参数  \n",{"type":19,"tag":1223,"props":5614,"children":5615},{"class":1225,"line":3258},[5616],{"type":19,"tag":1223,"props":5617,"children":5618},{},[5619],{"type":25,"value":5620},"                    from_station = stations[get_from]  # 出发地  \n",{"type":19,"tag":1223,"props":5622,"children":5623},{"class":1225,"line":3267},[5624],{"type":19,"tag":1223,"props":5625,"children":5626},{},[5627],{"type":25,"value":5628},"                    to_station = stations[get_to]  # 目的地  \n",{"type":19,"tag":1223,"props":5630,"children":5631},{"class":1225,"line":3276},[5632],{"type":19,"tag":1223,"props":5633,"children":5634},{},[5635],{"type":25,"value":5636},"                    # 发送查询请求，并获取返回的信息  \n",{"type":19,"tag":1223,"props":5638,"children":5639},{"class":1225,"line":3285},[5640],{"type":19,"tag":1223,"props":5641,"children":5642},{},[5643],{"type":25,"value":5644},"                    data = query(get_date, from_station, to_station)  \n",{"type":19,"tag":1223,"props":5646,"children":5647},{"class":1225,"line":3294},[5648],{"type":19,"tag":1223,"props":5649,"children":5650},{},[5651],{"type":25,"value":5652},"                    self.checkBox_default()  # 调用取消勾选所有车次分类复选框  \n",{"type":19,"tag":1223,"props":5654,"children":5655},{"class":1225,"line":3303},[5656],{"type":19,"tag":1223,"props":5657,"children":5658},{},[5659],{"type":25,"value":5660},"                    if len(data) != 0:  # 判断返回的数据是否为空  \n",{"type":19,"tag":1223,"props":5662,"children":5663},{"class":1225,"line":3312},[5664],{"type":19,"tag":1223,"props":5665,"children":5666},{},[5667],{"type":25,"value":5668},"                        # 如果不是空的数据就将车票信息显示在表格中  \n",{"type":19,"tag":1223,"props":5670,"children":5671},{"class":1225,"line":3321},[5672],{"type":19,"tag":1223,"props":5673,"children":5674},{},[5675],{"type":25,"value":5676},"                        self.displayTable(len(data), 16, data)  \n",{"type":19,"tag":1223,"props":5678,"children":5679},{"class":1225,"line":3330},[5680],{"type":19,"tag":1223,"props":5681,"children":5682},{},[5683],{"type":25,"value":5684},"                    else:  \n",{"type":19,"tag":1223,"props":5686,"children":5687},{"class":1225,"line":3339},[5688],{"type":19,"tag":1223,"props":5689,"children":5690},{},[5691],{"type":25,"value":5692},"                        self.messageDialog('警告', '没有返回的网络数据！')  \n",{"type":19,"tag":1223,"props":5694,"children":5695},{"class":1225,"line":3348},[5696],{"type":19,"tag":1223,"props":5697,"children":5698},{},[5699],{"type":25,"value":3390},{"type":19,"tag":1223,"props":5701,"children":5702},{"class":1225,"line":3357},[5703],{"type":19,"tag":1223,"props":5704,"children":5705},{},[5706],{"type":25,"value":5707},"                    self.messageDialog('警告','超出查询日期的范围内,不可查询昨天的车票信息,以及29天以后的车票信息！')  \n",{"type":19,"tag":1223,"props":5709,"children":5710},{"class":1225,"line":3366},[5711],{"type":19,"tag":1223,"props":5712,"children":5713},{},[5714],{"type":25,"value":5715},"            else:  \n",{"type":19,"tag":1223,"props":5717,"children":5718},{"class":1225,"line":3375},[5719],{"type":19,"tag":1223,"props":5720,"children":5721},{},[5722],{"type":25,"value":5723},"                self.messageDialog('警告', '输入的站名不存在,或日期格式不正确！')  \n",{"type":19,"tag":1223,"props":5725,"children":5726},{"class":1225,"line":3384},[5727],{"type":19,"tag":1223,"props":5728,"children":5729},{},[5730],{"type":25,"value":5731},"        else:  \n",{"type":19,"tag":1223,"props":5733,"children":5734},{"class":1225,"line":3393},[5735],{"type":19,"tag":1223,"props":5736,"children":5737},{},[5738],{"type":25,"value":5739},"            self.messageDialog('警告', '请填写车站名称！')  \n",{"type":19,"tag":1223,"props":5741,"children":5742},{"class":1225,"line":3402},[5743],{"type":19,"tag":1223,"props":5744,"children":5745},{},[5746],{"type":25,"value":2724},{"type":19,"tag":1223,"props":5748,"children":5749},{"class":1225,"line":3411},[5750],{"type":19,"tag":1223,"props":5751,"children":5752},{},[5753],{"type":25,"value":5754},"        self.messageDialog('警告', '未下载车站查询文件！')\n",{"type":19,"tag":32,"props":5756,"children":5757},{},[5758,5760,5765],{"type":25,"value":5759},"8）在",{"type":19,"tag":165,"props":5761,"children":5763},{"className":5762},[],[5764],{"type":25,"value":1745},{"type":25,"value":5766},"方法中，首先设置出发日期的编辑框中显示系统的当前日期，然后设置查询按钮的单击事件，最后分别设置高铁、动车、直达、特快以及快车复选框选中与取消事件。关键代码如下：",{"type":19,"tag":1213,"props":5768,"children":5770},{"className":1215,"code":5769,"language":1217,"meta":7,"style":7},"self.textEdit_3.setText(get_time())\nself.pushButton.clicked.connect(self.on_click)  \nself.checkBox_G.stateChanged.connect(self.change_G)  \nself.checkBox_D.stateChanged.connect(self.change_D)  \nself.checkBox_Z.stateChanged.connect(self.change_Z)  \nself.checkBox_T.stateChanged.connect(self.change_T)  \nself.checkBox_K.stateChanged.connect(self.change_K)  \nself.checkBox_O.stateChanged.connect(self.change_O)  \nself.checkBox_F.stateChanged.connect(self.change_F)  \nself.checkBox_EMU.stateChanged.connect(self.change_EMU)  \nself.checkBox_ALL.stateChanged.connect(self.change_ALL)\n",[5771],{"type":19,"tag":165,"props":5772,"children":5773},{"__ignoreMap":7},[5774,5782,5790,5798,5806,5814,5822,5830,5838,5846,5854],{"type":19,"tag":1223,"props":5775,"children":5776},{"class":1225,"line":1226},[5777],{"type":19,"tag":1223,"props":5778,"children":5779},{},[5780],{"type":25,"value":5781},"self.textEdit_3.setText(get_time())\n",{"type":19,"tag":1223,"props":5783,"children":5784},{"class":1225,"line":1235},[5785],{"type":19,"tag":1223,"props":5786,"children":5787},{},[5788],{"type":25,"value":5789},"self.pushButton.clicked.connect(self.on_click)  \n",{"type":19,"tag":1223,"props":5791,"children":5792},{"class":1225,"line":1244},[5793],{"type":19,"tag":1223,"props":5794,"children":5795},{},[5796],{"type":25,"value":5797},"self.checkBox_G.stateChanged.connect(self.change_G)  \n",{"type":19,"tag":1223,"props":5799,"children":5800},{"class":1225,"line":1253},[5801],{"type":19,"tag":1223,"props":5802,"children":5803},{},[5804],{"type":25,"value":5805},"self.checkBox_D.stateChanged.connect(self.change_D)  \n",{"type":19,"tag":1223,"props":5807,"children":5808},{"class":1225,"line":1262},[5809],{"type":19,"tag":1223,"props":5810,"children":5811},{},[5812],{"type":25,"value":5813},"self.checkBox_Z.stateChanged.connect(self.change_Z)  \n",{"type":19,"tag":1223,"props":5815,"children":5816},{"class":1225,"line":1271},[5817],{"type":19,"tag":1223,"props":5818,"children":5819},{},[5820],{"type":25,"value":5821},"self.checkBox_T.stateChanged.connect(self.change_T)  \n",{"type":19,"tag":1223,"props":5823,"children":5824},{"class":1225,"line":1385},[5825],{"type":19,"tag":1223,"props":5826,"children":5827},{},[5828],{"type":25,"value":5829},"self.checkBox_K.stateChanged.connect(self.change_K)  \n",{"type":19,"tag":1223,"props":5831,"children":5832},{"class":1225,"line":1394},[5833],{"type":19,"tag":1223,"props":5834,"children":5835},{},[5836],{"type":25,"value":5837},"self.checkBox_O.stateChanged.connect(self.change_O)  \n",{"type":19,"tag":1223,"props":5839,"children":5840},{"class":1225,"line":1403},[5841],{"type":19,"tag":1223,"props":5842,"children":5843},{},[5844],{"type":25,"value":5845},"self.checkBox_F.stateChanged.connect(self.change_F)  \n",{"type":19,"tag":1223,"props":5847,"children":5848},{"class":1225,"line":1412},[5849],{"type":19,"tag":1223,"props":5850,"children":5851},{},[5852],{"type":25,"value":5853},"self.checkBox_EMU.stateChanged.connect(self.change_EMU)  \n",{"type":19,"tag":1223,"props":5855,"children":5856},{"class":1225,"line":1421},[5857],{"type":19,"tag":1223,"props":5858,"children":5859},{},[5860],{"type":25,"value":5861},"self.checkBox_ALL.stateChanged.connect(self.change_ALL)\n",{"type":19,"tag":32,"props":5863,"children":5864},{},[5865],{"type":25,"value":5866},"（9）在window.py文件下，单击右键，选择“Run 'window'”菜单运行主窗体，然后输入符合规范的出发地、目的地与出发日期，单击查询按钮将显示如图35所示。",{"type":19,"tag":32,"props":5868,"children":5869},{},[5870],{"type":19,"tag":50,"props":5871,"children":5874},{"alt":5872,"src":5873},"Pasted image 20250801224854","\u002Fimages\u002Fblog\u002Ftrain-tickets\u002FPasted%20image%2020250801224854.png",[],{"type":19,"tag":5876,"props":5877,"children":5878},"style",{},[5879],{"type":25,"value":5880},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":7,"searchDepth":1235,"depth":1235,"links":5882},[5883,5884,5885,5889,5890,5891],{"id":22,"depth":1235,"text":26},{"id":57,"depth":1235,"text":60},{"id":115,"depth":1235,"text":115,"children":5886},[5887,5888],{"id":137,"depth":1244,"text":140},{"id":1001,"depth":1244,"text":1001},{"id":2146,"depth":1235,"text":2146},{"id":2248,"depth":1235,"text":2248},{"id":2755,"depth":1235,"text":2755,"children":5892},[5893,5894],{"id":2763,"depth":1244,"text":2766},{"id":4517,"depth":1244,"text":4520},"markdown","content:blog:2025-08-01-train-tickets.md","content","blog\u002F2025-08-01-train-tickets.md","blog\u002F2025-08-01-train-tickets","md",1780801018181]