当前位置:网站首页>14行代码完成任意选择图片爬取
14行代码完成任意选择图片爬取
2022-04-22 06:12:00 【欣慰的三叶草(● ̄(エ) ̄●)】
14行代码完成任意选择图片爬取
方法一
import requests
import re
# 获取源网页
url = 'http://www.duoziwang.com/head/wenzi/644597.html'
r = requests.get(url)
url_jpg = re.findall('src="(http.*?.jpg)"', r.text)
# 获取图片地址
for i in url_jpg:
response = requests.get(i)
filename = r"C:\Users\dell\Desktop\png\{}.png".format(i[-10:])
# 下载保存图片
with open(filename, "wb") as f:
f.write(response.content)
print('图片{}下载成功,已保存到桌面png文件夹中!'.format(i[-10:]))
```
方法二
import requests
import re
# 获取源网页
url = 'https://image.baidu.com/search/index?ct=201326592&cl=2&st=-1&lm=-1&nc=1&ie=utf-8&tn=baiduimage&ipn=r&rps=1&pv=&fm=rs4&word=%E6%88%91%E5%A7%93%E6%9B%B9&oriquery=%E6%88%91%E5%A7%93%E6%9B%B9%E7%9A%84%E9%9C%B8%E6%B0%94%E6%96%87%E5%AD%97%E5%9B%BE%E7%89%87&ofr=%E6%88%91%E5%A7%93%E6%9B%B9%E7%9A%84%E9%9C%B8%E6%B0%94%E6%96%87%E5%AD%97%E5%9B%BE%E7%89%87&hs=2&sensitive=0'
r = requests.get(url)
url_jpg = re.findall('"(https://.*?.jpg)"', r.text)
# 获取图片地址
j = 0
for i in url_jpg:
j += 1
response = requests.get(i)
filename = r"C:\Users\dell\Desktop\png\{}.png".format(i[-24: -15])
# 下载保存图片
with open(filename, "wb") as f:
f.write(response.content)
print('图片{}下载成功,已保存到桌面png文件夹中!'.format(j))
print('******第{}张图片下载完成!******'.format(j))

版权声明
本文为[欣慰的三叶草(● ̄(エ) ̄●)]所创,转载请带上原文链接,感谢
https://blog.csdn.net/cygqtt/article/details/106492518
边栏推荐
- 【JEECG】修改Viser图表颜色样式
- .NET学习笔记----关于.NET Core那些事(1)【.netcore的项目结构、五种向页面传值的方式、Log4Net和NLog的使用】
- 【Bug小记】页面刷新后获取不到sessionstorage数据
- Notes on C # daily development ----- obtain all files in the zip in Huawei cloud bucket (including system. Notsupportedexception: "this stream does not support search operation" solution)
- 阿里云部署RSSHub踩坑笔记
- format()方法的格式控制
- 阿里云部署Tiny Tiny RSS踩坑笔记
- Goodbye, postman. One thing to say: apifox is yyds
- Application of mcicecan in industrial computer
- ASP.NET日常开发随手记------导出Excel
猜你喜欢

Relationship between Nacos namespace grouping and dataid

Nacos persistent switch configuration

左移与右移

First order digital low-pass filter - C language / Matlab implementation

模二除运算的上商原则

阿里云部署RSSHub踩坑笔记

Nacos服务提供者注册

安裝和修改uTools及vscode插件安裝路徑

作用域与生存期(翁恺老师)

From spec. to chip_ (Digital IC, analog IC, FPGA / CPLD design process and EDA tools)
随机推荐
Nacos集群架构
pyftpdlib中文乱码问题解决方案
CLion和动态链接库
ASP.NET日常开发随手记------iis服务器支持下载apk
短路
【Bug小记】antd表格高度自适应窗口高度
分布式任务调度与计算框架:PowerJob 高级特性-容器 03
送给所有程序员的新年祝福&新年愿望
Distributed task scheduling and computing framework: powerjob quick start (local ide version) 02
leetcode268:丢失的数字
C daily development notes -- solve the problem that one set references another set, resulting in changes together
分页
MySQL完全卸载,mysql服务清理
ASP.NET日常开发随手记------后台执行js脚本
New year's greetings & wishes to all programmers
Scope and lifetime (Mr. Weng Kai)
ParseException Unparseable date 时间转换异常
利用线程工厂设定线程池中线程名称
Digital IC design, after learning Verilog syntax, what else do you need to learn?
ASP.NET日常开发随手记------导出Excel