正则表达式在HTML中查找<img src='url' />

0 投票
1 回答
2464 浏览
提问于 2025-04-17 18:18

我还没有玩过正则表达式,想找一些帮助来提取字符串中的特定部分。

这是一个图片标签的例子:

<img border="0" alt="background, images, scarica, adobe, art, rainbow, colorful, wallpaper, tutorial, abstract, photoshop, web, pictures, wallpapers" width="192" height="120" class="h_120" src="http://static.hdw.eweb4.com/media/thumbs/1/74/736679.jpg" />

我只是想从一个很大的HTML文件中提取出src的URL。

1 个回答

2

使用 BeautifulSoup

from bs4 import BeautifulSoup

soup = BeautifulSoup(html_doc)
page_images = [image["src"] for image in soup.findAll("img")]

安装 BeautifulSoup 的方法是:在命令行输入 pip install beautifulsoup4

撰写回答