https://www.ecust.edu.cn/
时间: 2023-08-15 13:03:42 浏览: 51
好的,根据您提供的网站,我会编写一个简单的 Python 爬虫程序,使用 requests 和 BeautifulSoup 库来爬取图片。以下是代码实现:
```python
import requests
from bs4 import BeautifulSoup
import os
# 创建保存图片的文件夹
save_dir = "ecust_images"
if not os.path.exists(save_dir):
os.mkdir(save_dir)
# 发送请求并解析 HTML
url = "https://www.ecust.edu.cn/"
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")
# 找到所有的图片标签
img_tags = soup.find_all("img")
# 遍历所有的图片标签,下载图片并保存到文件夹中
for img_tag in img_tags:
img_url = img_tag.get("src")
if img_url.startswith("http"):
response = requests.get(img_url)
# 提取图片文件名
img_name = img_url.split("/")[-1]
with open(os.path.join(save_dir, img_name), "wb") as f:
f.write(response.content)
```
请将以上代码复制到一个 Python 文件中,运行即可。爬取的图片将保存在当前目录下的 `ecust_images` 文件夹中。注意,由于网站的图片可能存在版权问题,请勿将程序用于商业用途。