user agent为Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
时间: 2024-01-21 18:02:57 浏览: 175
'''模拟浏览器头部信息'''headers = 'User-Agent': 'Mozilla/5.0 (
好的,您可以在发送请求时添加 headers 参数来设置请求头信息,其中包括 User-Agent 信息。以下是一个示例代码:
```python
import requests
url = "https://api.maersk.com/oceanProducts/mcpu/futureschedules"
params = {
"from": "2IW9P6J7XAW72",
"to": "0XOP5ISJZK0HR",
"containerIsoCode": "42G1",
"fromServiceMode": "CY",
"toServiceMode": "CY",
"numberOfWeeks": "4",
"dateType": "D",
"date": "2023-06-13",
"vesselFlag": "",
"cargoType": "DRY",
"containerType": "DRY",
"containerLength": "40",
"brandCode": "mcpu"
}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
}
response = requests.get(url, params=params, headers=headers)
if response.status_code == 200:
print(response.json())
else:
print("请求失败,状态码为:", response.status_code)
```
这段代码会向指定的 URL 发送一个 GET 请求,并传递指定的参数和请求头信息。如果请求成功,将会打印出响应的 JSON 数据。如果请求失败,将会打印出错误信息和状态码。需要注意的是,User-Agent 信息可以根据具体的需求进行修改。
阅读全文