我可以通过访问这个网址https://www.maersk.com.cn/schedules/pointToPoint,然后附加载荷进而访问刚才那个网址么
时间: 2023-08-09 12:10:02 浏览: 60
不建议直接通过访问 https://www.maersk.com.cn/schedules/pointToPoint 页面并携带所有请求参数来进行访问,因为该网站可能会对直接访问该页面的请求进行限制。相反,建议您通过分析该页面的请求过程,找到相应的API接口,然后通过API接口来获取数据。具体的步骤可以参考以下几点:
1. 打开 https://www.maersk.com.cn/schedules/pointToPoint 页面,并在浏览器的开发者工具中切换到“Network”标签页。
2. 在页面上填写所需的请求参数,并点击“Search”按钮。
3. 在开发者工具中可以看到该页面向服务器发送了一个名为“api/pointToPoint”的请求,这个请求返回了所需的数据。
4. 点击该请求,在右侧的“Headers”选项卡中可以看到该请求的URL,该URL包含了所有的请求参数。
5. 您可以使用该URL来获取数据,例如使用Python中的requests库进行请求。
请注意,在使用API接口获取数据时,也需要注意网站的爬虫协议,并避免频繁的请求。
相关问题
现在我想用request方法爬取https://www.maersk.com.cn/schedules/pointToPoint?from=2IW9P6J7XAW72&to=0XOP5ISJZK0HR&containerIsoCode=42G1&fromServiceMode=CY&toServiceMode=CY&numberOfWeeks=4&dateType=D&date=2023-06-13&vesselFlag=,我想爬取这个网页上的启运港、启运时间、目的港、到达时间、船名
好的,您可以使用Python的requests库来发起请求,然后使用BeautifulSoup库对HTML进行解析,提取所需的数据。下面是一个简单的示例代码:
```python
import requests
from bs4 import BeautifulSoup
url = "https://www.maersk.com.cn/schedules/pointToPoint"
params = {
"from": "2IW9P6J7XAW72",
"to": "0XOP5ISJZK0HR",
"containerIsoCode": "42G1",
"fromServiceMode": "CY",
"toServiceMode": "CY",
"numberOfWeeks": "4",
"dateType": "D",
"date": "2023-06-13",
"vesselFlag": "",
}
response = requests.get(url, params=params)
soup = BeautifulSoup(response.text, "html.parser")
for row in soup.select(".table-row"):
departure_port = row.select_one(".departure-port").text.strip()
departure_time = row.select_one(".departure-time").text.strip()
arrival_port = row.select_one(".arrival-port").text.strip()
arrival_time = row.select_one(".arrival-time").text.strip()
vessel_name = row.select_one(".vessel-name").text.strip()
print(f"船名:{vessel_name},启运港:{departure_port},启运时间:{departure_time},目的港:{arrival_port},到达时间:{arrival_time}")
```
在上面的代码中,我们首先定义了目标URL和请求参数,然后使用requests库发起GET请求。接着,我们使用BeautifulSoup库对响应内容进行解析,通过CSS选择器来选取每一行数据,并提取所需的信息。最后,我们将数据打印出来,或者保存到文件中,根据实际需求进行处理。
需要注意的是,该网站可能有反爬机制,为了避免被网站封禁IP,我们需要设置合适的请求头和代理IP等信息。另外,如果需要爬取多个搜索结果的数据,可以参考前面的回答,使用循环遍历多个搜索条件。
import requestsfrom bs4 import BeautifulSoupfrom datetime import datetimeurl = "https://www.maersk.com.cn/schedules/pointToPoint"today = datetime.today().strftime("%Y-%m-%d")params = { "from": "2IW9P6J7XAW72", "to": "0XOP5ISJZK0HR", "containerIsoCode": "42G1", "fromServiceMode": "CY", "toServiceMode": "CY", "numberOfWeeks": "4", "dateType": "D", "date": today, # 将当前日期格式化为字符串,并作为请求参数传递 "vesselFlag": "",}response = requests.get(url, params=params)soup = BeautifulSoup(response.text, "html.parser")for row in soup.select(".table-row"): departure_port = row.select_one(".departure-port").text.strip() departure_time = row.select_one(".departure-time").text.strip() arrival_port = row.select_one(".arrival-port").text.strip() arrival_time = row.select_one(".arrival-time").text.strip() vessel_name = row.select_one(".vessel-name").text.strip() print(f"船名:{vessel_name},启运港:{departure_port},启运时间:{departure_time},目的港:{arrival_port},到达时间:{arrival_time}")
这是一个使用 Python 爬取马士基航运网站船期信息的代码,具体来说,该代码使用了 requests 库和 BeautifulSoup 库对网页进行了爬取和解析,然后输出了船名、启运港、启运时间、目的港和到达时间等信息。其中,params 参数是请求参数,通过构造参数可以获取不同的船期信息,具体含义可以参考马士基航运网站的 API 文档。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)