吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 8876|回复: 28
收起左侧

[Python 转载] Python 随机更换美女桌面壁纸(可修改自己喜欢的风格桌面壁纸)【4个网站】【附带...

  [复制链接]
凹凸曼大人 发表于 2020-12-27 20:10
本帖最后由 凹凸曼大人 于 2020-12-27 23:16 编辑

先发于自己博客! 最近逛吾爱破解,就发出来,大家看看美女洋洋眼
目前可以随即选取4个网站中一张美女图片,来作为壁纸。
[Python] 纯文本查看 复制代码
import random
import requests
from lxml import etree
from fake_useragent import UserAgent
import win32api
import win32gui
import win32con
import os
import re
import urllib

def set_wallpaper(bmp_path):
    # 打开指定注册表路径
    reg_key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE)
    # 最后的参数:2拉伸,0居中,6适应,10填充,0平铺
    win32api.RegSetValueEx(reg_key, "WallpaperStyle", 0, win32con.REG_SZ, "2")
    # 最后的参数:1表示平铺,拉伸居中等都是0
    win32api.RegSetValueEx(reg_key, "TileWallpaper", 0, win32con.REG_SZ, "0")
    # 刷新桌面
    win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,bmp_path, win32con.SPIF_SENDWININICHANGE)
class bizhi_360():
    def __init__(self):
        bizhi_360 = ['http://bizhi360.com/meinv/list_{}.html'.format(i) for i in range(48)]
        bizhi_360_one = random.choice(bizhi_360)
        wang_zhan = [bizhi_360_one]
        self.a = random.choice(wang_zhan)
    def huoqu(self):

          # 模拟访问者
        ua = UserAgent().random
        headers = {"User-Agent": ua}
        data = requests.get(url=self.a, headers=headers)
        data.encoding= "utf-8"
        data= data.text
        s = etree.HTML(data)
        meinv_liebiao = s.xpath('//*[@id="main"]/div/div[1]/ul/li/a//@href')
        if len(meinv_liebiao) >1 :
            meinv = random.choice(meinv_liebiao)
            s = 'http://bizhi360.com'
            url = s + meinv
            self.xiazai(url)
        else:
            pass
    def xiazai(self,url):
        ua = UserAgent().random
        headers = {"User-Agent": ua}
        data = requests.get(url=url, headers=headers)
        data.encoding = "utf-8"
        data =data.text
        s = etree.HTML(data)
        meinv_tupian = s.xpath('//*[@id="main"]/div/div[1]/div[2]/ul/li/a//@href')
        if len(meinv_tupian) >1 :
            meinv = random.choice(meinv_tupian)
            s = 'http://bizhi360.com'
            url1 = s + meinv
            print(url1)
            self.xiazai_tupian(url1)
        else:
            meinv_url = s.xpath('//*[@id="main"]/div/div[1]/div[2]/figure/a//@href')
            try:
                url = meinv_url[0]
                response = requests.get(url,headers=headers)
                # 获取的文本实际上是图片的二进制文本
                img = response.content
                # 将他拷贝到本地文件 w 写  b 二进制  wb代表写入二进制文本
                # 保存路径
                path1 = os.getcwd()
                path = path1 + '\\1.jpg'
                with open(path, 'wb') as f:
                    f.write(img)
            except Exception as ex:
                print("出错")

    def xiazai_tupian(self,url1):
        ua = UserAgent().random
        headers = {"User-Agent": ua}
        data = requests.get(url=url1, headers=headers)
        data.encoding = "utf-8"
        data = data.text
        s = etree.HTML(data)
        meinv_tupian = s.xpath('//*[@id="main"]/div[1]/div[1]/div[2]/figure/a//@href')
        try:
            url = meinv_tupian[0]
            response = requests.get(url,headers=headers)
            # 获取的文本实际上是图片的二进制文本
            img = response.content
            # 将他拷贝到本地文件 w 写  b 二进制  wb代表写入二进制文本
            # 保存路径
            path1 = os.getcwd()
            path = path1+ '\\1.jpg'
            with open(path, 'wb') as f:
                f.write(img)
        except Exception as ex:
            print("--------出错继续----")


class k4_bizhi():
    def __init__(self):
        num = random.randint(1,171)
        bizhi_360 = ('http://pic.netbian.com/4kmeinv/index_{}.html'.format(num))
        self.a = bizhi_360
    def huoqu(self):
        ua = UserAgent().random
        headers = {"User-Agent": ua}
        data = requests.get(url=self.a, headers=headers)
        data.encoding = "utf-8"
        data = data.text
        s = etree.HTML(data)
        meinv_liebiao = s.xpath('//*[@id="main"]/div[3]/ul/li/a//@href')
        if len(meinv_liebiao) >1 :
            meinv = random.choice(meinv_liebiao)
            s = 'http://pic.netbian.com'
            url = s + meinv
            self.xiazai(url)
        else:
            pass
    def xiazai(self,url):
        ua = UserAgent().random
        headers = {"User-Agent": ua}
        data = requests.get(url=url, headers=headers)
        data.encoding = "utf-8"
        data = data.text
        s = etree.HTML(data)
        meinv_tupian = s.xpath('//*[@id="img"]/img//@src')
        try:
            s = 'http://pic.netbian.com'
            url1 = s + meinv_tupian[0]
            response = requests.get(url1, headers=headers)
            # 获取的文本实际上是图片的二进制文本
            img = response.content
            # 将他拷贝到本地文件 w 写  b 二进制  wb代表写入二进制文本
            # 保存路径
            path1 = os.getcwd()
            path = path1 + '\\1.jpg'
            with open(path, 'wb') as f:
                f.write(img)
        except Exception as ex:
            print("--------出错继续----")

class k4_weimei():
    def __init__(self):
        num = random.randint(1, 6)
        bizhi_360 = ('http://www.4kbizhi.com/meinv/index_{}.html'.format(num))
        self.a = bizhi_360
    def huoqu(self):

          # 模拟访问者
        ua = UserAgent().random
        headers = {"User-Agent": ua}
        data = requests.get(url=self.a, headers=headers)
        data.encoding= "utf-8"
        data= data.text
        s = etree.HTML(data)
        meinv_liebiao = s.xpath('/html/body/div[2]/div[1]/ul/li/a//@href')
        meinv_liebiao1 = s.xpath('/html/body/div[2]/div[2]/ul/li/a//href')
        meinv_lie = meinv_liebiao +meinv_liebiao1
        if len(meinv_lie) >1 :
            meinv = random.choice(meinv_liebiao)
            meinv= meinv.replace('.html', '')
            s = 'http://www.4kbizhi.com'
            url = s + meinv + '-1920x1080' +'.html'
            self.xiazai(url)
        else:
            pass
    def xiazai(self,url):
        ua = UserAgent().random
        headers = {"User-Agent": ua}
        data = requests.get(url=url, headers=headers)
        data.encoding = "utf-8"
        data =data.text
        s = etree.HTML(data)
        meinv_tupian = s.xpath('/html/body/div[2]/img//@src')[0]
        b = meinv_tupian.replace('small', '')
        c = b.split('/')
        c.pop()
        c = '/'.join(c)
        b = b.split('/')[-1]
        b = b[:11]
        meinv_tupian_url = c + '/' + b + '.jpg'
        try:
            s = 'http://www.4kbizhi.com'
            url1 = s + meinv_tupian_url
            response = requests.get(url1,headers=headers)
            # 获取的文本实际上是图片的二进制文本
            img = response.content
            # 将他拷贝到本地文件 w 写  b 二进制  wb代表写入二进制文本
            # 保存路径
            path1 = os.getcwd()
            path = path1 + '\\1.jpg'
            with open(path, 'wb') as f:
                f.write(img)
        except Exception as ex:
            print("出错")
class tupian_zhijia():
    def __init__(self):
        num = random.randint(1, 11)
        bizhi_360 = ('https://www.tupianzj.com/bizhi/DNmeinv/list_77_{}.html'.format(num))
        self.a = bizhi_360
    def huoqu(self):

          # 模拟访问者
        ua = UserAgent().random
        headers = {"User-Agent": ua}
        data = requests.get(url=self.a, headers=headers)
        data.encoding= "utf-8"
        data= data.text
        s = etree.HTML(data)
        meinv_liebiao = s.xpath('//*[@id="container"]/div/div/div[3]/div/ul/li/a//@href')

        if len(meinv_liebiao) >1 :
            meinv = random.choice(meinv_liebiao)
            meinv= meinv.replace('.html', '')
            s = 'https://www.tupianzj.com'
            url = s + meinv + '_1920x1080' +'.html'
            self.xiazai(url)
        else:
            pass
    def xiazai(self,url):
        ua = UserAgent().random
        headers = {"User-Agent": ua}
        data = requests.get(url=url, headers=headers)
        data.encoding = "utf-8"
        data = data.text
        meinv_tupian = re.findall(r"if\(imgSize==\"1920x1080\"\) picurl='.*",data)
        meinv_tupian = ''.join(meinv_tupian)
        meinv_tupian = meinv_tupian.replace('\'', '')
        meinv_tupian = meinv_tupian.replace(';', '')
        meinv_tupian =  meinv_tupian.split('=')[-1]
        meinv_tupian1 = ''.join(meinv_tupian)
        self.xiazai_tupian(meinv_tupian1)
    def xiazai_tupian(self,url1):
        try:
            ua = UserAgent().random
            url = str(url1)
            headers = {"User-Agent": ua}
            request = urllib.request.Request(url, headers=headers)
            response = urllib.request.urlopen(request)
            # 获取的文本实际上是图片的二进制文本
            img = response.read()
            # response = requests.get(url, headers=headers)
            # img = response.content
            # 将他拷贝到本地文件 w 写  b 二进制  wb代表写入二进制文本
            # 保存路径
            path1 = os.getcwd()
            path = path1 + '\\1.jpg'
            with open(path, 'wb') as f:
                f.write(img)
        except Exception as ex:
            print("出错")


if __name__== '__main__':
    liebiao = [1,2,3,4]
    a= random.choice(liebiao)
    if a ==1:
        bizhi_360().huoqu()
    elif a==2:
        k4_bizhi().huoqu()
    elif a ==3:
        k4_weimei().huoqu()
    elif a==4:
        tupian_zhijia().huoqu()
    path1 = os.getcwd()
    path = path1 +"\\1.jpg"  # 图片路径
    try:
        set_wallpaper(path)
    except:
        print('图片为下载!')


来看效果图:
自己可以打包成exe文件,用win10自带的任务工具,设置成多久启动一次。也可以写成bat文件,在写成vbs启动bat文件去除代码框,放在桌面双击就换一站美女桌面壁纸。

应评论要求,怕有些人不会用这些代码,那就用 pyinstaller打包成exe可执行文件,有点大,这是python打包的缺点。
image.png
压缩成压缩包打包了。
最好用代码,写成bat文件,这样比较小。

地址https://aotumandaren.lanzouj.com/izB5Njs42ha
image.png

免费评分

参与人数 9吾爱币 +8 热心值 +7 收起 理由
7535668 + 1 + 1 谢谢@Thanks!
yu14758681 + 1 谢谢@Thanks!
Mr.yangloveYYQ + 1 我很赞同!
yjn866y + 1 + 1 我很赞同!
wangchenggang + 1 + 1 谢谢@Thanks!
Dragon_214 + 1 + 1 用心讨论,共获提升!
gi204657 + 1 谢谢@Thanks!
Alone7707 + 1 + 1 谢谢@Thanks!
TXWD东方不败 + 1 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 凹凸曼大人 发表于 2021-2-8 20:52
569xingfu 发表于 2021-2-4 16:47
win7 64位报错求解failed to execute pyi_rth_pkgres

这个是打包软件自带不兼容的问题,最好用我的源代码,放在自己电脑python上跑一下,换壁纸,写个bat脚本,调用python脚本,来实现自动换壁纸,我的win10 64位,以前系统 兼容不是很好。
 楼主| 凹凸曼大人 发表于 2021-4-22 21:10
maigaoren4016 发表于 2021-4-20 17:33
软件运行时不在任务栏显示吗?如何退出或关闭呢?

一次性的,运行一次就关闭了。要想多久更换一次壁纸,用系统任务计划,每隔多久运行一次。
浪里白跳 发表于 2020-12-27 20:15
TXWD东方不败 发表于 2020-12-27 20:25
谢谢分享
yoyoma211 发表于 2020-12-27 20:41
进来学习下,楼主给力
沉心云 发表于 2020-12-27 20:48
博主能再具体说明一下操作方法吗,小白有点难懂
gullbest 发表于 2020-12-27 20:51
多谢分享
 楼主| 凹凸曼大人 发表于 2020-12-27 21:03
沉心云 发表于 2020-12-27 20:48
博主能再具体说明一下操作方法吗,小白有点难懂

那我打包出来,再发出来吧。

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
xcnice + 1 + 1 谢谢@Thanks!

查看全部评分

shdily 发表于 2020-12-27 21:40
其实phython不见得有多精简,为什么近两年那么火呢?
Pdsdt 发表于 2020-12-27 21:41
照片是从web站点下载到本地的把,那换的多的话,是不是本地存储的照片就多起来了
heykuz 发表于 2020-12-27 21:42
电脑入门必备
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 11:33

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表