某乎问答:有哪些仙气四溢的星空壁纸嘛?
url: https://www.zhihu.com/question/439483198/answer/1680920607

安装package
因为下载了多个版本的python
因此需要在cmd内pip install 指定python版本

cd python.exe所在目录
python -m pip install package

python

from bs4 import BeautifulSoup
import requests
import os
from fake_useragent import UserAgentdef getImg(question_url, file_dir='.\pic', show=False):if not os.path.exists(file_dir):os.mkdir(file_dir)url = question_url#随机请求头headers = {'user-agent':UserAgent().random}response = requests.get(url=url, headers=headers)question = BeautifulSoup(response.text, "html.parser")img_list = question.select("figure > img")print (img_list)for index, img in enumerate(img_list):if img.has_attr('data-original'):print(img['data-original'])image = requests.get(img['data-original'])with open(file_dir + str(index) + '.jpg', "wb") as f:f.write(image.content)if __name__ == '__main__':getImg("https://www.zhihu.com/question/439483198/answer/1680920607", file_dir=".\pic\.", show=False)

同理爬取某壁纸网页的Sakura图片,只需要修改三个参数,原网页、子标签和属性即可定位图片的的url

from bs4 import BeautifulSoup
import requests
import osdef getImg(question_url, file_dir='.\pic', show=False):if not os.path.exists(file_dir):os.mkdir(file_dir)url = question_urlheaders = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36 Edg/85.0.564.51'}response = requests.get(url=url, headers=headers)question = BeautifulSoup(response.text, "html.parser")img_list = question.select("img[alt]")print (img_list)for index, img in enumerate(img_list):if img.has_attr('src'):print(img['src'])image = requests.get(img['src'])with open(file_dir + str(index) + '.jpg', "wb") as f:f.write(image.content)if __name__ == '__main__':getImg("https://unsplash.com/s/photos/sakura", file_dir=".\pic\.", show=False)

python爬虫爬取壁纸图片相关推荐

  1. python爬虫,爬取下载图片

    python爬虫,爬取下载图片 分别引入以下三个包 from urllib.request import urlopen from bs4 import BeautifulSoup import re ...

  2. Python爬虫爬取相关图片

    简要的实现实现Python爬虫爬取百度贴吧页面上的图片,下面的网页就是本篇博客所要爬的网页,当然看到的只是其中的一部分图片,是所要爬取的页面, 而下图则是最终的爬取的图片: 接下来就简要的讲讲爬取的整 ...

  3. python爬虫爬取网页图片_Python爬虫:爬取网页图片

    先分析查找要爬取图片的路径 在浏览器F12 审查元素 整体实现代码 # -- coding:UTF-8 -- import requests from bs4 import BeautifulSoup ...

  4. python爬虫爬取百度图片,python爬虫篇2:爬取百度图片

    入门级 import requests import re import os from urllib import error def main(): dirPath = "E:\pyth ...

  5. python爬虫爬取百度图片总结_python爬虫如何批量爬取百度图片

    当我们想要获取百度图片的时候,面对一张张图片,一次次的点击右键下载十分麻烦.python爬虫可以实现批量下载,根据我们下载网站位置.图片位置.图片下载数量.图片下载位置等需求进行批量下载,本文演示py ...

  6. 上手快!!福利局!新手如何使用python爬虫爬取网页图片(使用正则进行数据解析)当然这个新手是我自己

    作为一个python新入门小白,突然就想发个博客,一方面为了记录学习历程,一方面能分享给新入门的同学经验,更多的是想和大家一起学习和交流.以下是我以小白的角度分享的爬虫的相关知识和一个简单的爬取网页图 ...

  7. 利用python爬虫爬取斗鱼图片(简单详细)

    关于 在一个安静的夜晚,我缓慢的打开了电脑,望着已经睡着的父母,我轻轻的把门关上,看着斗鱼颜值主播的魅力,我不尽感叹,要是每天都可以不需要那么麻烦的去看那该有多好! 于是我想起了最近刚学的爬虫,嘴角露 ...

  8. Python爬虫爬取src图片

    Python爬虫爬取图片 需要用到的库: os time request lxml 代码源码如下: import os import time import requests from lxml im ...

  9. 超详细解析python爬虫爬取京东图片

    超详细图片爬虫实战 实例讲解(京东商城手机图片爬取) 1.创建一个文件夹来存放你爬取的图片 2.第一部分代码分析 3.第二部分代码分析 完整的代码如下所示: 升级版代码: 爬取过程中首先你需要观察在手 ...

最新文章

  1. Scalable IO in Java
  2. python抢票_50 个加速包都抢不到车票,还不如这个 Python 抢票神器!
  3. react 引用本地js_从零配置webpack 4+react脚手架(二)
  4. 一次前后端分离的实践
  5. 远程登录阿里云上的MySQL
  6. 2013年工作中遇到的20个问题:241-260
  7. 未来计算机的景象,科幻场景即将实现,未来云电脑!
  8. Xshell家庭版下载
  9. DeepMind登上Science:“和AI相比,人类都是猪队友”,团战称霸雷神之锤3
  10. DeepLearning | Broad Learning System 宽度学习系统 : 高效增量式浅层神经网络
  11. ndows 内存诊断工具,windows内存诊断工具有什么作用
  12. 小蚂蚁学cURL笔记(1)
  13. MPEG压缩中的 I、B、P帧
  14. eclipse,wtp配置
  15. 钢铁行业关键业务系统介绍
  16. 奇点临近:互联网经济的供给侧革命和全球货币政策的新格林斯潘之谜
  17. 数据库系统概论 | Exercise 1整理
  18. OTTO机器人之MAX7219点阵
  19. 解决EXP-00003问题
  20. jenkins插件下载地址

热门文章

  1. 短视频APP选择云服务器要注意哪些问题?
  2. 【第1158期】哔哩哔哩的前端之路
  3. 12个视频剪辑素材网站,短视频素材免费下。
  4. java国外研究综述,国内外研究现状_毕业论文
  5. Business 2.0评出2007年25大网络新锐(转)
  6. Bartender 自定义显示长度和填充规则
  7. 让自己的app出现在某类格式文件的默认打开列表中
  8. SourceTree 3x版本跳过登录
  9. 单片机逻辑取反和按位取反差异
  10. 09 PDM行业开门红 中船重工重庆川东造船厂联手迈特科技 实施PDM项目 加速船舶业发展