Python爬虫爬取一个网页上的图片地址实例代码
作者:powerpoint_2016 时间:2021-07-25 09:58:25
本文实例主要是实现爬取一个网页上的图片地址,具体如下。
读取一个网页的源代码:
import urllib.request
def getHtml(url):
html=urllib.request.urlopen(url).read()
return html
print(getHtml(http://image.baidu.com/search/flip?tn=baiduimage&ie=utf-8&word=%E5%A3%81%E7%BA%B8&ct=201326592&lm=-1&v=flip))
利用正则表达式爬取一个网页上的图片地址:
import re
import urllib.request
def getHtml(url):
html=urllib.request.urlopen(url).read()
return html
def getImg(html):
r=r'"thumbURL":"(http://img.+?\.jpg)"' #定义正则
imglist=re.findall(r,html)
return imglist
html=str(getHtml("http://image.baidu.com/search/flip?tn=baiduimage&ie=utf-8&word=%E5%A3%81%E7%BA%B8&ct=201326592&lm=-1&v=flip"))
print(getImg(html))
运行结果:
来源:http://blog.csdn.net/m0_38066258/article/details/77388350
标签:python,爬虫,图片
0
投稿
猜你喜欢
Python中struct模块对字节流/二进制流的操作教程
2021-05-10 19:26:56
Python网络编程详解
2022-01-09 15:25:10
ASP读取日期单日期自动补零函数代码
2011-02-20 10:39:00
基于Python数据可视化利器Matplotlib,绘图入门篇,Pyplot详解
2022-11-20 07:59:16
Python3安装psycopy2以及遇到问题解决方法
2022-12-19 15:41:26
ASP中的Debug类--VBScript
2008-10-24 09:38:00
python入门:argparse浅析 nargs='+'作用
2023-06-26 15:52:58
Pytorch中膨胀卷积的用法详解
2023-03-26 12:03:25
PHP 二维数组根据某个字段排序的具体实现
2023-11-20 05:21:13
使用Python手工计算x的算数平方根,来自中国古人的数学智慧
2021-12-07 01:29:53
php获取referer防非法访问
2023-08-20 11:30:58
Python多线程编程之多线程加锁操作示例
2023-11-01 00:37:19
使用python实现http及ftp服务进行数据传输的方法
2021-08-26 01:20:19
Python使用pip安装报错:is not a supported wheel on this platform的解决方法
2022-12-12 09:07:09
Python实现炸金花游戏的示例代码
2022-01-15 05:24:17
学用代码片段
2011-09-06 19:37:35
js实现圆形菜单选择器
2023-09-23 19:50:54
Python集合set的交集和并集操作方法
2023-12-25 17:35:56
Python UnicodedecodeError编码问题解决方法汇总
2023-10-07 09:28:20
Python Tkinter实例——模拟掷骰子
2022-09-17 09:51:07