以下是一个使用Python爬取写真网站全部图片的示例代码:
import requestsfrom bs4 import BeautifulSoupimport os# 定义写真网站的URLurl = '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)请注意,这只是一个示例代码,实际使用时需要根据具体的写真网站页面结构进行相应的修改和优化。另外,爬取网站的图片需要遵守网站的使用规范,以免侵犯他人的版权。

