酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

Python:用Pycharm实现爬取haowallpaper.com网站壁纸代码解析

import requests from bs4 import BeautifulSoup import os # 创建一个文件夹来保存下载的壁纸 os.makedirs('wallpapers', exist_ok=True) url = 'https://haowallpaper.com/' response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') wallpaper_links = soup.find_all('img', class_='attachment-full size-full wp-post-image') for link in wallpaper_links: image_url = link['src'] image_name = image_url.split('/')[-1] image_response = requests.get(image_url) with open(f'wallpapers/{image_name}', 'wb') as file: file.write(image_response.content) print('壁纸下载完成!') ######[AI写代码神器 | 411点数解答 | 2024-10-28 17:44:35]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]