python如何获取网页中指定的图片保存的路径

时间:2026-02-12 23:43:49

1、引入正则和采集库:

import re  //正则模块

import urllib //urllib 模块提供了读取web页面数据的接口

python如何获取网页中指定的图片保存的路径

python如何获取网页中指定的图片保存的路径

2、先根据url 获取,对应的页面数据:

定义函数getHtml().

def getHtml(url):

    page = urllib.urlopen(url) //打开链接

    html = page.read() //读取页面数据

    return html

python如何获取网页中指定的图片保存的路径

3、然后各根据获取图片路径的需求设定正则表达式:

定义函数getImg(html).

代码如图:

python如何获取网页中指定的图片保存的路径

python如何获取网页中指定的图片保存的路径

4、运行测试

python如何获取网页中指定的图片保存的路径

© 2026 五度知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com