彼岸图网是一个比较好的壁纸网站,有需要的可以去付费支持下载高清大图,貌似还可以打包下载,
[color=]这里不是打广告
只是告诉大家有这么一个可以下载壁纸的地方
以下是源码
[Python] 纯文本查看 复制代码import requests
import os
import time
from bs4 import BeautifulSoup
import tkinter as tk
from tkinter import messagebox
from tkinter import filedialog
from tkinter import Toplevel # 用于创建弹出窗口
# 1cm 约等于 37.795276 像素
CM_TO_PIXEL = 37.795276
def get_li_hrefs(url, save_folder, progress_window, progress_label):
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
}
try:
response = requests.get(url, headers=headers)
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
lis = soup.find_all('li')
links = []
for li in lis:
link = li.find('a')
if link:
href = link.get('href')
if href and '/tupian' in href: # 筛选条件
full_url = 'https://pic.netbian.com' + href # 拼接完整的 URL
links.append(full_url)
image_count = 1 # 初始化图片计数
for link in links: # 依次请求筛选后的链接并处理返回内容
try:
link_response = requests.get(link)
if link_response.status_code == 200:
link_soup = BeautifulSoup(link_response.text, 'html.parser')
photo_pic_divs = link_soup.find_all('div', class_='photo-pic')
for div in photo_pic_divs:
img_tags = div.find_all('img')
for img in img_tags:
src = img.get('src')
full_src = 'https://pic.netbian.com' + src # 拼接完整的 URL
# 处理保存图片的文件夹,如果不存在则创建
if not os.path.exists(save_folder):
os.makedirs(save_folder)
# 下载图片并按照自然数重命名保存到指定文件夹
try:
time.sleep(1) # 每次请求之间延时 1 秒
image_response = requests.get(full_src)
if image_response.status_code == 200:
new_image_name = str(image_count) + '.jpg' # 重命名为自然数.jpg
save_path = os.path.join(save_folder, new_image_name)
with open(save_path, 'wb') as f:
f.write(image_response.content)
progress_label.config(text=f"正在下载,已下载 {image_count} 张图片") # 更新标签文本
progress_window.update() # 更新窗口显示
print(f"图片重命名为 {new_image_name} 已保存到 {save_path}")
image_count += 1 # 图片计数加 1
else:
print(f"请求图片 {full_src} 失败,状态码: {image_response.status_code}")
except requests.exceptions.RequestException as e:
print(f"请求图片 {full_src} 出错: {e}")
else:
print(f"请求链接 {link} 失败,状态码: {link_response.status_code}")
except requests.exceptions.RequestException as e:
print(f"请求链接 {link} 出错: {e}")
# 下载完成后关闭进度窗口并弹出下载完成窗口
progress_window.destroy()
completed_window = Toplevel(root)
completed_window.title("下载完成")
completed_window.geometry(f"{int(9 * CM_TO_PIXEL)}x{int(6 * CM_TO_PIXEL)}")
completed_label = tk.Label(completed_window, text="下载完成!", font=("Helvetica", 16), justify="center", fg="green") # 设置字体为绿色
completed_label.pack(expand=True)
completed_window.mainloop()
else:
print(f"请求失败,状态码: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"请求出错: {e}")
def start_download():
url = url_entry.get()
if url:
save_folder = folder_entry.get() # 获取用户输入的保存文件夹
if not save_folder: # 如果未输入,使用默认文件夹
save_folder = 'D:\\images'
progress_window = Toplevel(root)
progress_window.title("下载进度")
progress_window.geometry(f"{int(9 * CM_TO_PIXEL)}x{int(6 * CM_TO_PIXEL)}")
progress_label = tk.Label(progress_window, text="正在下载,已下载 0 张图片", font=("Helvetica", 16), justify="center")
progress_label.pack(expand=True)
get_li_hrefs(url, save_folder, progress_window, progress_label)
else:
messagebox.showerror("错误", "请输入有效的 URL")
# 创建主窗口
root = tk.Tk()
root.title("图片下载工具")
# 设置窗口大小(9cm x 6cm 转换为像素,假设 1cm = 37.795276px)
width_px = int(9 * CM_TO_PIXEL)
height_px = int(6 * CM_TO_PIXEL)
root.geometry(f"{width_px}x{height_px}")
# URL 输入框
url_label = tk.Label(root, text="输入 URL:")
url_label.pack()
url_entry = tk.Entry(root)
url_entry.pack()
# 保存文件夹输入框
folder_label = tk.Label(root, text="保存文件夹:")
folder_label.pack()
folder_entry = tk.Entry(root)
folder_entry.pack()
# 选择文件夹按钮
folder_button = tk.Button(root, text="选择文件夹", command=lambda: set_folder(folder_entry))
folder_button.pack()
# 下载按钮
download_button = tk.Button(root, text="开始下载", command=start_download)
download_button.pack()
def set_folder(entry_widget):
folder_selected = filedialog.askdirectory()
if folder_selected:
entry_widget.delete(0, tk.END)
entry_widget.insert(0, folder_selected)
root.mainloop()
软件地址永久有效:https://lgkl.lanzout.com/iwDxG2fzp97e
密码:fddp
下载完壁纸之后,可以通过 Photoshop这类图片处理工具或者一些 AI 工具,手动将壁纸变得更清晰。不知道有没有大佬知道能够通过这个 Python 编写一个程序,对接这个 AI 工具,让这个图片自动变得清晰,或者说是自动操作PS,类似于这样的程序
不足之处请各位大佬批评指正,共同进步!