以下是一个使用Python爬取写真网站全部图片的示例代码:
import requests from bs4 import BeautifulSoup import os # 定义写真网站的URL url = 'https://example.com' # 发送请求获取网页内容 response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') # 在网页中查找图片链接 image_links = [] for img in soup.find_all('img'): image_links.append(img['src']) # 创建保存图片的文件夹 os.makedirs('images', exist_ok=True) # 下载图片并保存到本地 for link in image_links: response = requests.get(link) filename = os.path.join('images', link.split('/')[-1]) with open(filename, 'wb') as f: f.write(response.content) print('Saved', filename)
请注意,这只是一个示例代码,实际使用时需要根据具体的写真网站页面结构进行相应的修改和优化。另外,爬取网站的图片需要遵守网站的使用规范,以免侵犯他人的版权。