猫眼电影api连接代码
时间: 2023-12-08 14:04:13 浏览: 220
以下是一个使用 Python 的 requests 库连接猫眼电影 API 的示例代码:
```python
import requests
url = "https://api.maoyan.com/mmdb/movie/v3/list/hot.json"
params = {
"limit": "10",
"offset": "0",
"ci": "1",
"token": "",
"utm_campaign": "AmovieBmovieCD-1",
"utm_source": "migu",
"movieBundleVersion": "10202",
"webp": "1",
"utm_medium": "android",
"platform": "ios",
"utm_term": "8.2.0",
"appVersion": "8.2.0",
"utm_content": "860656038042015"
}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299",
"Referer": "https://maoyan.com/films"
}
response = requests.get(url, params=params, headers=headers)
if response.status_code == 200:
data = response.json()
# 处理返回的数据
else:
print(f"请求失败,错误代码:{response.status_code}")
```
以上代码是获取热门电影的示例,其中 `url` 和 `params` 中的参数可以根据具体的 API 接口进行修改,并根据需要添加请求头 `headers`。
阅读全文