#!/usr/bin/python
# encoding=utf-8
import requests
from bs4 import BeautifulSoup
class bizhi:
def getheaders(self):
return {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,**;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Host": "pic.bizhi360.com",
"If-Modified-Since": "Wed, 01 Sep 2021 14:24:33 GMT",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36",
}
def getImg(self,img_html):
details_html = BeautifulSoup(img_html.content.decode('utf-8'), 'html.parser')
img_url = details_html.find('figure').find('a').get('href')
title = details_html.find('title').getText()
img_html = requests.get(img_url, headers=self.imgheader())
img_html_c = img_html.content
ext = img_url.split('.') # 获取后缀名
with open('./img/' + str(title) + "." + str(ext[3]), 'wb') as f:
f.write(img_html_c)
f.close()
if __name__ == '__main__':
x = bizhi()
# x.getHtml("http://www.bizhi360.com/meinv") #http://www.bizhi360.com/meinv/list_2.html
for i in range(2,100):
try:
x.getHtml(
"http://www.bizhi360.com/meinv/list_" + str(i) + ".html") # http://www.bizhi360.com/meinv/list_2.html
except Exception:
print('1')
定时切换壁纸代码
#!/usr/bin/python
# encoding=utf-8
import threading
import os
import random
import ctypes
def change_background():
# 注意文件夹路径
rootdir = 'c:/www/python/img'
for parent, dirnames, filenames in os.walk(rootdir):
file_names = filenames
x = random.randint(0, len(file_names)-1)
file_path = rootdir+"/"+filenames[x]
ctypes.windll.user32.SystemParametersInfoW(20, 0, file_path, 3)
def timer():
# 5分钟切换一次
t = threading.Timer(300,change_background)
t.start()
if __name__ == '__main__':
timer()



