1.爬取图片,作为壁纸,用来接下来的壁纸自动切换
python代码里的库如果报错,记得下库
pip install 加库名

代码

import requests
import parsel# 10,15爬取10到15页的图片
for pag in range(10, 15):print(f'=========={pag}页=====')# 设置网页url = f'http://www.netbian.com/meinv/index_{pag}.htm'# 设置浏览器headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'}#responrse = requests.get(url=url, headers=headers)# html_data = responrse.content.decode('utf-8')responrse.encoding = responrse.apparent_encoding# print(responrse.text)selctor = parsel.Selector(responrse.text)lis = selctor.css('.list li')# print(lis)for li in lis:title = li.css('b::text').get()# print(title)if title:href = 'http://www.netbian.com/' + li.css('a::attr(href)').get()# print(href, title)response_i = requests.get(url=href, headers=headers)seletor_i = parsel.Selector(response_i.text)img_url = seletor_i.css('.pic img::attr(src)').get()# print(href,title,img_url)img_countent = requests.get(url=img_url, headers=headers).content# 图片保存在当前img目录下with open('img\\' + title + '.jpg', mode='wb') as f:f.write(img_countent)print('正在保存:' + title)

设置浏览器

运行代码,图片保存在img目录下

2.编写自动切换壁纸代码

import random
import ctypes
import time
import datetime
import os
from xml.dom.minidom import parsepicture_list = []
path = ""
random_time = 68def read_xml():doc = parse("./config.xml")root = doc.documentElementglobal path,random_timepath = root.getElementsByTagName("path")[0].firstChild.datarandom_time = int(root.getElementsByTagName("random_time")[0].firstChild.data)def list_all_pic(pic_dir):pic_files = []files_list  =os.listdir(pic_dir)for i in range(0,len(files_list)):full_path = os.path.join(pic_dir,files_list[i])if os.path.isfile(full_path):if full_path.rsplit(".")[-1].lower() in ["jpg","bmp","jpeg","png"]:pic_files.append(full_path)return pic_files
def random_pic_index():return picture_list[random.randint(0,len(picture_list)-1)]def main():read_xml()global picture_listpicture_list = list_all_pic(path)if len(picture_list) == 0:print("文件夹中没有壁纸")exit(1)while True:file_name = random_pic_index()ctypes.windll.user32.SystemParametersInfoW(20,0,file_name,0)print("{} 图像名:{}".format(datetime.datetime.strftime(datetime.datetime.now(),"%y-%m-%d %H:%M:%S"),file_name))time.sleep(random_time)if __name__ == '__main__':main()```python

编写.xml文件

<?xml version="1.0"?>
<config>
<!--    保存图片目录--><path>F:/python/pythonFile/wallpaper/img</path>
<!--    图片切换时间--><random_time>60</random_time>
</config>

运行桌面查看效果

**

3.打包成exe文件

**
1.win+R
cmd 打开命令行窗口
首先安装pyinstaller,使用安装命令:pip3 install pyinstaller
2.找到python文件夹运行cmd回车打开命令行

运行命令 pyinstaller -F 文件名.py
成功后 项目dist目录下有exe程序,把他移到.py文件同一目录

双击运行

3.添加到系统自启文件夹,实现开机自启

1.创建快捷方式
2.命令行打开自启文件夹(shell:startup),放入快捷方式

壁纸实现开机自启自动切换

python 爬取图片 壁纸开机自启自动切换相关推荐

  1. 用python爬取图片的一点小结

    一.原理小结 最近在学习用python的爬虫爬取网络上的图片,制作数据集并用于后续的一些实验.看了很多关于python爬取图片的介绍,并验证了相关代码,先推荐几个介绍比较好的爬虫过程: [1]小白爬虫 ...

  2. python爬取图片然后保存在文件夹中

    python爬取图片然后保存在文件夹中 直接上代码: import os import requests import redef getimg(soup,i):print('http:'+ soup ...

  3. python爬取图片并保存到本地

    Python爬取图片(你懂得) requests与Bs4 这两个模块是本文使用的主要模块,requests可以获取连接,bs4全名BeautifulSoup,是编写python爬虫常用库之一,主要用来 ...

  4. Python爬取图片、视频以及将数据写入excel的方法小摘要

    Python爬取图片.视频以及将数据写入excel的方法小摘要 1.爬取图片 2.爬取视频 3.将获取的数据存入excel 4.备注 1.爬取图片 import requests #导入request ...

  5. Python——爬取图片

    大家好,我是@xiaomeng 小孟 您好 欢迎大家阅读今天的文章----Python爬取图片(爬虫) 最近爬虫挺火的,所以我今天也来一个爬虫! 正文: 首先,我们先下载模块,pip install ...

  6. python爬取图片链接标签的src属性值_python爬取图片遇见src乱码: data:image/png;base64...

    python爬取图片遇见src乱码: data:image/png;base64 向爬取自己喜欢的图片,但是在爬取下来的代码当中图片的src会出现乱码的情况:data:image/png;base64 ...

  7. Python爬取图片实例

    网络爬虫又叫网络蜘蛛.网络机器人等名词.网络爬虫就是自动化的去抓取网络数据,可以在网络中获取满足自己需求的相关信息和资料.通过网络爬虫可以获取大量的数据并且集中在一起,然后就可以进行数据的批量分析和处 ...

  8. python爬取图片并写入excel

    目标: 1)python爬取图片并下载到本地文件夹 2)python爬取图片并写入到excel文件 Ⅰ.python程序 # 导入库 import requests import parsel imp ...

  9. php直播源码,python爬取图片

    php直播源码,python爬取图片的相关代码 import requests import osfrom bs4 import BeautifulSoupheaders = {'user-agent ...

最新文章

  1. opencv 修改图像数值_opencv 修改图像数值_Python中使用OpenCV读取像素
  2. qq浏览器主页_QQ浏览器遭恶意病毒篡改主页,无法更改的解决办法
  3. 数学图形(1.46)高次方程曲线
  4. 为什么8位有符号数的取值范围是-128~+127
  5. idea 使用maven构建项目时,target bytecode version经常自动变化
  6. P4173-残缺的字符串【FFT】
  7. stl min函数_std :: min()函数以及C ++ STL中的示例
  8. Go 语言学习总结(4)—— 为什么说 Golang 是面向未来的语言?
  9. 去中心化借贷协议24小时清算超1300万美元
  10. JAVA day06 继承,super,方法的重写,抽象类
  11. 【笔试/面试】—— 有向无环图(DAG)的最短路径问题(动态规划)
  12. java读取txt文件内容 乱码_java读取txt文件乱码解决方法
  13. 北大青鸟php培训怎么样,北大青鸟php培训怎么样
  14. Android 蓝牙 ble 随机地址深层次分析
  15. C#双色球——简单抽取中奖号码
  16. 乐优商城(三十九)—— 订单中心
  17. mldonkey 的使用
  18. 分享65个NET源码,总有一款适合您
  19. 开机计算机丢失opencl.dll,win10无法修复Opencl.dll的解决方法教程|win10修复Opencl.dll的方法教程...
  20. c++图像处理入门教程

热门文章

  1. 稻盛和夫-活法.书评(zz.IS2120@BG57IV3)
  2. 算法: n个元素进栈,共有多少种出栈顺序?
  3. 谈谈数据库连接池的原理
  4. 安装补丁“此更新不适用于你的计算机”解决办法
  5. 最值得珍藏的50个生活小窍门
  6. 我的世界android启动器,blocklauncher pro我的世界启动器
  7. asp.net ajax怎样传值,JQuery在asp.net中三种ajax传值
  8. PRGC Potential Relation and Global Correspondence Based Joint Relational Triple Extraction
  9. 高效项目的七个习惯-转载
  10. 【2017cs231n】:课程笔记-第2讲:图像分类