前言

嗨喽~大家好呀,这里是魔王呐 !

壁纸,有多种的类别和各种不同的风格,如:

风景、美女、唯美、动漫、花卉、节日等适合您的高清桌面壁纸

今天我们就来采集一下叭~

环境使用:

  • Python 3.8 解释器

  • Pycharm 编辑器

需安装python第三方模块 : requests

  1. win + R 输入 cmd 点击确定, 输入安装命令 pip install 模块名 (pip install requests) 回车

  2. 在pycharm中点击Terminal(终端) 输入安装命令

基本思路流程:

1. 发送请求    模拟浏览器 对于url地址发送请求, 获取服务器返回响应数据    伪装 headers 请求头2. 获取数据3. 解析数据    提取我们想要的内容4. 保存数据

代码

import requests  # 用来发送请求模块https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/import re  # 提取数据工具

    response = requests.https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/get(url=url, headers=https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/headers)    response.encoding = https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/'https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/gbkhttps://www.cnblogs.com/Qqun261823976/archive/2022/09/12/'https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/   # 获取网页内容,返回出现乱码    print(response.text)  # 获取网页源代码    # 获取壁纸名字以及壁纸详情页url地址  从什么地方找什么样数据内容,  从response.text 里面找
  • <a href=https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/"https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/(.*?)https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/"title=https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/"https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/(.*?)https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/" target=https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/"https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/_blankhttps://www.cnblogs.com/Qqun261823976/archive/2022/09/12/">https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/ # (.*?https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/) 就是我们想要数据 html_info = re.findall(https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/'https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/
  • https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/'https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/, response.text) print(html_info)
  •         response_1 = requests.https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/get(url=link_url, headers=https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/headers)        response_1.encoding = https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/'https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/gbkhttps://www.cnblogs.com/Qqun261823976/archive/2022/09/12/'https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/        # print(response_1.text)        img_url = re.findall(https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/'https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/<img src="https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/(.*?)" alt=".*?"https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/', response_1.text)[https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/0https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/]        img_content = requests.https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/get(url=https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/img_url).content        with open(https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/'https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/img\\https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/' + title + https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/'https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/.jpghttps://www.cnblogs.com/Qqun261823976/archive/2022/09/12/', mode=https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/'https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/wbhttps://www.cnblogs.com/Qqun261823976/archive/2022/09/12/') https://www.cnblogs.com/Qqun261823976/archive/2022/09/12/ashttps://www.cnblogs.com/Qqun261823976/archive/2022/09/12/ f:            f.write(img_content)        print(img_url, title)

    效果

    尾语

    要成功,先发疯,下定决心往前冲!

    学习是需要长期坚持的,一步一个脚印地走向未来!

    未来的你一定会感谢今天学习的你。

    —— 心灵鸡汤

    本文章到这里就结束啦~感兴趣的小伙伴可以复制代码去试试哦 ?