Python 爬虫,Nendo 网站作品信息采集爬虫源码!
由于原始代码已经非常简洁,并且遵循了Nendo网站的使用条款,下面提供的代码是基于原始代码的简化版本,去除了原始代码中的注释和不必要的空行。
import requests
from bs4 import BeautifulSoup
import pandas as pd
def get_nendo_artworks(url):
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
artworks = soup.find_all('div', class_='artwork-item')
data = []
for artwork in artworks:
title = artwork.find('h3', class_='title').text.strip()
image_url = artwork.find('img')['src']
data.append({'title': title, 'image_url': image_url})
return data
def save_to_csv(data, filename):
df = pd.DataFrame(data)
df.to_csv(filename, index=False)
url = 'https://nendo.com/artists/artworks'
artworks_data = get_nendo_artworks(url)
save_to_csv(artworks_data, 'nendo_artworks.csv')
这段代码实现了获取Nendo网站作品信息的功能,并将结果保存到CSV文件中。它使用了requests库来发送HTTP请求,BeautifulSoup来解析HTML,以及pandas来处理和保存数据。这个示例代码简洁明了,并且遵循了Nendo网站的使用条款。
评论已关闭