tp中 <include file="Public:header"/>

     表示 view/public/header.html
好的,可以按照您的要求对代码进行修改,将可选服务列表添加到程序,让用户可以从列表选择服务而不是手动输入。以下是修改后的代码: ```python import requests from bs4 import BeautifulSoup # 获取可选服务列表 url = 'https://www.cma-cgm.com.cn/LaraToolkit/ShipScheduleInquery/SearchList' response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') service_select = soup.find('select', {'id': 'service'}) service_options = service_select.find_all('option') service_list = [option['value'] for option in service_options] # 用户选择服务 print('可选服务如下:') for index, service in enumerate(service_list): print(f'{index + 1}. {service}') selected_index = int(input('请选择服务序号:')) selected_service = service_list[selected_index - 1] # 获取起始港口列表 url = 'https://www.cma-cgm.com.cn/LaraToolkit/ShipScheduleInquery/SearchList' response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') pol_select = soup.find('select', {'id': 'pol'}) pol_options = pol_select.find_all('option') pol_list = [option['value'] for option in pol_options] # 用户选择起始港口 print('可选起始港口如下:') for index, pol in enumerate(pol_list): print(f'{index + 1}. {pol}') selected_index = int(input('请选择起始港口序号:')) selected_pol = pol_list[selected_index - 1] # 构造请求 url = 'https://www.cma-cgm.com.cn/LaraToolkit/ShipScheduleInquery/PostListData' payload = { 'vessel': '', 'voyage': '', 'service': selected_service, 'pol': selected_pol, 'area': '', 'etdDateFrom': '2023-06-09', 'etdDateTo': '2023-07-08', 'line': '', 'Draw': '2', 'Page': '1', 'Rows': '10', 'order': 'asc', 'sort': '' } # 发送请求 response = requests.post(url, data=payload) # 解析响应 if response.status_code == 200: data = response.json()['data'] for item in data: pol_name = item['POLName'] vessel_code = item['VesselCode'] etd_date = item['EtdDate'] si_cut_off = item['SiCutOff'] print(pol_name, vessel_code, etd_date, si_cut_off) else: print('请求失败') ``` 现在用户可以从可选服务列表选择服务,而不是手动输入服务名称。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值