我试图从HTML img标记中提取图像源URL。如何使用正则表达式提取img标签中的src?
如果HTML数据如下图所示:
<div> My profile <img width='300' height='300' src='http://domain.com/profile.jpg'> </div>
或
<div> My profile <img width="300" height="300" src="http://domain.com/profile.jpg"> </div>
如何在Python中的正则表达式?
我曾试过如下:
i = re.compile('(?P<src>src=[["[^"]+"][\'[^\']+\']])')
i.search(htmldata)
,但我得到一个错误
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
您是否已尝试创建自己的正则表达式;这将有助于 – Evert
上面的两行代码不会给你那个错误。 – Evert
[Python正则表达式字符串抽取]可能的重复(http://stackoverflow.com/questions/7384275/python-regex-string-extraction) – ozy