自动查询12306余票,结果以txt形式放到nginx网站目录下
1 #!/bin/bash 2 3 # yum install glibc-common jq 4 5 6 date=2024-01-01 7 from=BJP 8 to=HBB 9 10 echo -en "$date from $from to $to \n查询时间:$(date)\n\n" > /usr/share/nginx/html/tmp.txt 11 echo -en "1(硬座) | 2(软座) | 3(硬卧) | 4(软卧) | 6(高级软卧) | 9(商务座)\n" >> /usr/share/nginx/html/tmp.txt 12 echo -en "O(二等座) | M(一等座) | J(二等卧) | I(一等卧) | S(二等包座) | P(特等座) | F(动卧)\n\n" >> /usr/share/nginx/html/tmp.txt 13 echo 14 15 curl -s 'https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date='$date'&leftTicketDTO.from_station='$from'&leftTicketDTO.to_station='$to'&purpose_codes=ADULT' --compressed -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0' -H 'Accept: */*' -H 'Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2' -H 'Accept-Encoding: gzip, deflate, br' -H 'If-Modified-Since: 0' -H 'Cache-Control: no-cache' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Referer: https://kyfw.12306.cn/otn/leftTicket/init?linktypeid=dc' -H 'Cookie: JSESSIONID=351872DE4733CB94A610989260012D83; tk=yFup9wLsOrHqqNDDRVgPCjdfqG87vYN8tvv95Atyw1w0; RAIL_EXPIRATION=1681383442403; RAIL_DEVICEID=HV-tI8xMLrqpzRMJEe9YfB3Sj0vBSCFzlcQanOK0XYgZEH8ZZVm7xKMsqm6HA_qG4MlDCw2FkZ7FZBRqGeZeKn6LhP3ftdD0DObRbg_5Ee_U_tD91l5n-5rdHd4OpJ4A45fUJhJMQR6_RkXhLPvd11LYK8LEZZyY; _jc_save_fromStation=%u8861%u6C34%2CHSP; _jc_save_toStation=%u5317%u4EAC%2CBJP; _jc_save_fromDate=2023-07-09; _jc_save_toDate=2023-06-26; _jc_save_wfdc_flag=dc; guidesStatus=off; highContrastMode=defaltMode; cursorStatus=off; fo=undefined; _jc_save_showIns=true; BIGipServerotn=434635018.50210.0000; BIGipServerpassport=870842634.50215.0000; route=6f50b51faa11b987e576cdb301e545c4; uKey=cc8bb03c007982bc98a9fe90eb51cef3f27b7c71ee14e32a4badf979b75fd24c; current_captcha_type=Z' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-origin' -H 'Pragma: no-cache' \ 16 | jq .data.result[] \ 17 | sed \ 18 -e 's/FTP/丰台站/g' \ 19 -e 's/BJP/北京站/g' \ 20 -e 's/BXP/北京西/g' \ 21 -e 's/IFP/朝阳站/g' \ 22 -e 's/FTP/丰台站/g' \ 23 -e 's/VAB/哈西站/g' \ 24 -e 's/VBB/哈东站/g' \ 25 -e 's/HBB/哈尔滨/g' \ 26 -e 's/IS_TIME_NOT_BUY/X/g'\ 27 -e 's/<br\/>//g'\ 28 | awk \ 29 -F \| \ 30 -v OFS='\t' \ 31 'BEGIN {print "车次\t出发站\t到达站\t出发时\t到达时\t耗时\t软一卧\t硬二卧\t二等座\t软座\t硬座\t无座\t有无票\t坐席类\t可候补\t起售否\n-----------------------------------------------------------------------------------------------------------------------------------"} 32 {print $4,$7,$8,$9,$10,$11,$24,$29,$31,$25,$30,$27,$12,$36,$39,$2}' \ 33 >> /usr/share/nginx/html/tmp.txt 34 35 iconv -f UTF-8 -t GB2312 /usr/share/nginx/html/tmp.txt -o /usr/share/nginx/html/12306.txt