酷代码 AI
菜单
服务商

https://haowallpaper.com/写一个爬取该网站壁纸的pycharm爬虫代码

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('壁纸下载完成!') [2024-10-28 17:44:35 | AI写代码神器 | 411点数解答]

相关提问
实用工具查看更多
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]
数独游戏 [娱乐类]
经典推箱子 [娱乐类]
AI摸鱼五子棋 [娱乐类]