我有一个看起来像这样的字符串
<table border="0" cellpadding="2" cellspacing="3"><tr><td><img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRO8iLLBmxFL2lvSfboTwwmH3yGF12PdsJe56rTAzJtbsFfS07I1YM_ZzavbwJREe7bUmhFR3ATyA" border="1"></td><td><ol style="list-style: none; margin: 0; padding: 0;"><strong><li><a href="http://newsday.co.tt/2017/11/14/ansa-mcal-sends-5-containers-of-relief-items/" target="_blank">ANSA McAl sends 5 containers of relief items</a> <font color="#6f6f6f">Trinidad News</font></li></strong><a href="https://news.google.com/story/?hl=en&ned=us" target="_blank">Full coverage</a></ol></td></tr></table>
我想要的是提取图像标记的来源。有关从何处开始实现此目的的任何建议?
答案 0 :(得分:0)
您可以使用.split()
,这是尝试从字符串中提取相关数据时非常有用的方法:
'<table border="0" cellpadding="2" cellspacing="3"><tr><td><img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRO8iLLBmxFL2lvSfboTwwmH3yGF12PdsJe56rTAzJtbsFfS07I1YM_ZzavbwJREe7bUmhFR3ATyA" border="1"></td><td><ol style="list-style: none; margin: 0; padding: 0;"><strong><li><a href="http://newsday.co.tt/2017/11/14/ansa-mcal-sends-5-containers-of-relief-items/" target="_blank">ANSA McAl sends 5 containers of relief items</a> <font color="#6f6f6f">Trinidad News</font></li></strong><a href="https://news.google.com/story/?hl=en&ned=us" target="_blank">Full coverage</a></ol></td></tr></table>'
.split('src="')[1]
.split('"')[0]
基本上,这可以做到以下几点:
src="
"
还有其他方法可以做到这一点(例如,正则表达式)。