python爬虫阴阳师式神技能
时间: 2023-12-28 16:05:29 浏览: 168
以下是一个使用Python爬虫获取阴阳师式神技能的示例代码:
```python
import requests
from bs4 import BeautifulSoup
import os
# 创建保存图片的文件夹
def create_folder(path):
if not os.path.exists(path):
os.mkdir(path)
# 下载图片
def download_image(url, path):
response = requests.get(url)
with open(path, 'wb') as f:
f.write(response.content)
# 爬取阴阳师式神技能
def crawl_shishen_skills():
# 阴阳师式神名称列表
shishen_name = ['式神1', '式神2', '式神3']
# 创建保存图片的文件夹
create_folder("C:/Users/diana/PycharmProjects/爬虫/图片/阴阳师/")
for ii in range(len(shishen_name)):
# 创建式神文件夹
os.mkdir("C:/Users/diana/PycharmProjects/爬虫/图片/阴阳师/"+shishen_name[ii])
# 切换到式神文件夹
os.chdir("C:/Users/diana/PycharmProjects/爬虫/图片/阴阳师/"+shishen_name[ii])
# 爬取式神技能页面
url = "http://www.example.com/式神技能页面" # 替换为实际的式神技能页面链接
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# 获取技能图片链接并下载
skill_images = soup.find_all('img', class_='skill-image')
for i, image in enumerate(skill_images):
image_url = image['src']
image_path = shishen_name[ii] + "_skill" + str(i+1) + ".jpg"
download_image(image_url, image_path)
# 调用爬取函数
crawl_shishen_skills()
```
请注意,上述代码中的链接和路径需要根据实际情况进行替换。此外,你还需要安装`requests`和`beautifulsoup4`库。
阅读全文