Hi. ! Hello everyone , This is the devil ~
Find a good wallpaper website , It's full of Ultra HD pictures
therefore , I'm going to collect all these wallpaper , Then I'm making a script to automatically change the desktop wallpaper , In this way, you can basically have a non repetitive desktop every day for a year
Let's take a look at our victims this time : https://wallhaven.cc/
It's a website with very high picture quality
import requests
import re
for page in range(1, 126):
url = 'https://wallhaven.cc/toplist?page={}'.format(page)
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'
}
response = requests.get(url=url, headers=headers)
urls = re.findall('<a class="preview" href="(.*?)"', response.text)
for i in urls:
response_2 = requests.get(url=i, headers=headers)
img_url = re.findall('<img id="wallpaper" src="(.*?)"', response_2.text)[0]
title = img_url.split('-')[-1]
download(title, img_url)
print(img_url)
def download(title, url):
path = 'img\\' + title
response = requests.get(url=url)
with open(path, mode='wb') as f:
f.write(response.content)
def Windows_img(paperPath):
k=win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control panel\\Desktop",0,win32con.KEY_SET_VALUE)
# Write attribute values in the registry
win32api.RegSetValueEx(k,"wapaperStyle",0,win32con.REG_SZ,"2") # 0 Represents the center of the desktop 2 Stands for stretched desktop
win32api.RegSetValueEx(k,"Tilewallpaper",0,win32con.REG_SZ,"0")
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,paperPath,win32con.SPIF_SENDWININICHANGE) # Refresh the desktop
def changeWallpaper():
""" Folder / Folder / picture """
path=input(' Please enter the file path :')
L2=os.listdir(path=path) # Get the wallpaper folder under the file path , List the type
i=0
print(L2) # Wallpaper folder
url_list = []
for l2 in L2:
detail_path = path + '\\' + l2
L3 = os.listdir(detail_path) # Get the picture under the wallpaper folder path , List the type
for l3 in L3:
url_list.append(detail_path + '\\' + l3)
print(url_list)
while True:
Windows_img(url_list[i])
print('{}'.format(url_list[i]))
time.sleep(2) # Set wallpaper replacement interval , Here for 10 second , Set the number of seconds according to the user's own needs
i += 1
if i == len(url_list): # If it's the last picture , Then go back to the first one
i = 0
def changeWallpaper_2():
""" Folder / picture """
path=input(' Please enter the file path :')
L2=os.listdir(path=path) # Get the picture under the file path , List the type
i=0
print(L2)
while True:
Windows_img(path+'\{}'.format(L2[i]))
print(path+'\{}'.format(L2[i]))
time.sleep(1000) # Set wallpaper replacement interval , Here for 10 second , Set the number of seconds according to the user's own needs
i += 1
if i==len(L2): # If it's the last picture , Then go back to the first one
i=0
if __name__ == '__main__':
changeWallpaper()
Okay , My article ends here !
There are more suggestions or questions to comment on or send me a private letter ! Come on together and work hard (ง •_•)ง
If you like, just pay attention to the blogger , Or like the collection and comment on my article !!!