截取html字符串
郁闷,这个该怎么做。。。。
以获取的字符串如下
<P align=center> <IMG src= "http://www1.ff369.com/2006/08/20/7/1.jpg "> </P>
<P align=center> <IMG src= "http://www1.ff369.com/2006/08/20/7/2.jpg "> </P>
<P align=center> <IMG src= "http://www1.ff369.com/2006/08/20/7/3.jpg "> </P>
<P align=center> <IMG src= "http://www1.ff369.com/2006/08/20/7/4.jpg "> </P>
<P align=center> <IMG src= "http://www1.ff369.com/2006/08/20/7/5.jpg "> </P>
<P align=center> <IMG src= "http://www1.ff369.com/2006/08/20/7/6.jpg "> </P>
<P align=center> <IMG src= "http://www1.ff369.com/2006/08/20/7/7.jpg "> </P>
处理后获取第一个IMG的值,即src= "http://www1.ff369.com/2006/08/20/7/1.jpg
请说明思路以及方法
------解决方案--------------------Response.Write(Regex.Replace( " <P align=center> <IMG src=\ "http://www1.ff369.com/2006/08/20/7/1.jpg\ "> </P> ", @ " <img\s+(? <src> src= " "?[^ " "\s> ]* " "?)> ", "${src} ", RegexOptions.IgnoreCase));
------解决方案--------------------如果可能这样
<P align=center> <IMG border= "1 " ............. src=\ "http://www1.ff369.com/2006/08/20/7/1.jpg\ " adddd.......> </P>
Response.Write(Regex.Replace( " <P align=center> <IMG src=\ "http://www1.ff369.com/2006/08/20/7/1.jpg\ "> </P> ", @ " <img\s+.*?(? <src> src= " "?[^ " "\s> ]* " "?).*?> ", "${src} ", RegexOptions.IgnoreCase));
------解决方案--------------------正则啊~!
string sourceString = @ " <P align=center> <IMG src= " "http://www1.ff369.com/2006/08/20/7/1.jpg " "> </P>
<P align=center> <IMG src= " "http://www1.ff369.com/2006/08/20/7/2.jpg " "> </P>
<P align=center> <IMG src= " "http://www1.ff369.com/2006/08/20/7/3.jpg " "> </P>
<P align=center> <IMG src= " "http://www1.ff369.com/2006/08/20/7/4.jpg " "> </P>
<P align=center> <IMG src= " "http://www1.ff369.com/2006/08/20/7/5.jpg " "> </P>
<P align=center> <IMG src= " "http://www1.ff369.com/2006/08/20/7/6.jpg " "> </P>
<P align=center> <IMG src= " "http://www1.ff369.com/2006/08/20/7/7.jpg " "> </P> ";
System.Text.RegularExpressions.MatchCollection results = Regex.Matches(sourceString,@ "src= " "([^ " "]*) ",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
foreach(Match result in results)
{
WL(result.Groups[1].Value);
}
//////////////////////////////////////////////
MSN:bdbox@hotmail.com请给我一个与您交流的机会!
------解决方案--------------------string str = " <P align=center> <IMG src=\ "http://www1.ff369.com/2006/08/20/7/1.jpg\ "> </P> ";
str = str.Replace( " <P align=center> <IMG src=\ " ", " ");
str = str.Replace( "\ "> </P> ", " ");