栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python3爬取壁纸图片,python3切换壁纸

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python3爬取壁纸图片,python3切换壁纸

#!/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()

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/354956.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号