2013-03-07 61 views
0

我还没有玩过正则表达式,并正在寻找一些帮助,以找到字符串中的部分。正则表达式在html中找到<img src='url' />

例IMG标签:

<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" />

我只是试图让SRC的URL了大量HTML文件。

+2

使用HTML解析器。 – SLaks 2013-03-07 19:06:50

+1

它已经被一次又一次地说过了,但是你不应该使用正则表达式来解析HTML,这不是一种常规的语言。你使用哪种语言? – 2013-03-07 19:07:20

+0

你真的需要阅读[这是关于在HTML上使用正则表达式的问题](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – 2013-03-07 19:07:29

回答

2

使用BeautifulSoup

from bs4 import BeautifulSoup 

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

使用安装BeautifulSouppip install beautifulsoup4