【发布时间】:2012-06-13 21:14:06
【问题描述】:
如何使用正则表达式通过Python从下面的html字符串中获取图片的src
<td width="80" align="center" valign="top"><font style="font-size:85%;font-family:arial,sans-serif"><a href="http://news.google.com/news/url?sa=t&amp;fd=R&amp;usg=AFQjCNFqz8ZCIf6NjgPPiTd2LIrByKYLWA&amp;url=http://www.news.com.au/business/spain-victory-faces-market-test/story-fn7mjon9-1226390697278"><img src="//nt3.ggpht.com/news/tbn/380jt5xHH6l_FM/6.jpg" alt="" border="1" width="80" height="80" /><br /><font size="-2">NEWS.com.au</font></a></font></td>
我尝试使用
matches = re.search('@src="([^"]+)"',text)
print(matches[0])
但一无所获
【问题讨论】:
-
“@”字符应该匹配什么?您的输入字符串中没有这样的字符。
-
正则表达式和html?
标签: python html regex html-parsing