我想匹配html中所有的
<td> <a href="http://tw.page.bid.yahoo.com/tw/auction/b64121666?u=Y6611727893"><img src="http://tw.bid.yimg.com/ac/29/85/b64121666-ac-2463xf10x0600x0450-s.jpg"/></a></td>然后提取href的值和src的值,请高手赐教啊。
注:a标记和img标记必须要同时匹配。
小弟愚笨,只能把a和img分开匹配:
匹配所有的a标记:(<a href=\")(\\w+[a-zA-Z0-9.-?=/]*)
匹配所有的img标记:(<img src=\")(\\w+[a-zA-Z0-9.-?=/]*)
<td> <a href="http://tw.page.bid.yahoo.com/tw/auction/b64121666?u=Y6611727893"><img src="http://tw.bid.yimg.com/ac/29/85/b64121666-ac-2463xf10x0600x0450-s.jpg"/></a></td>然后提取href的值和src的值,请高手赐教啊。
注:a标记和img标记必须要同时匹配。
小弟愚笨,只能把a和img分开匹配:
匹配所有的a标记:(<a href=\")(\\w+[a-zA-Z0-9.-?=/]*)
匹配所有的img标记:(<img src=\")(\\w+[a-zA-Z0-9.-?=/]*)
解决方案 »
- 使用Login控件DestinationPageUrl属性实现登录返回请求页面
- 求助
- asp.net将查询出来的结果放入DataSet中,然后怎么将表中内容放入ArrayList里return出来啊??
- OA办公自动化
- 如何定位一个项目到底用B/S还是C/S结构来的合理.
- 新手问题:如何在应用中锁定一条记录,防止其他人在同一时间内修改该记录
- DataGrid布局的问题,中间出现空格
- 高手们aspchart控件的StripLine的宽度调整的问题
- 类似lightbox的弹出网页渐变效果
- 狂送分(100):关于使用Microsoft.Office.Interop.Word.ApplicationClass的问题
- 连接数据库问题
- GridView中的input(text)数据绑定与数据回传,头大了!!
Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""\s]?)(?<href>[^'""\s]+)\1[^>]*?>\s*<img[^>]*?src=(['""\s]?)(?<src>[^'""\s]+)\2[^>]*?>");
foreach (Match m in reg.Matches(str))
{
Console.WriteLine(m.Groups["href"].Value);
Console.WriteLine(m.Groups["src"].Value);
} Console.ReadLine();
/*
http://tw.page.bid.yahoo.com/tw/auction/b64121666?u=Y6611727893
http://tw.bid.yimg.com/ac/29/85/b64121666-ac-2463xf10x0600x0450-s.jpg
*/
Regex reg = new Regex(@"(?is)(?<=<td[^>]*?>(?:(?!</?td).)*)<a[^>]*?href=(['""\s]?)(?<href>[^'""\s]+)\1[^>]*?>\s*<img[^>]*?src=(['""\s]?)(?<src>[^'""\s]+)\2[^>]*?>");
foreach (Match m in reg.Matches(str))
{
Console.WriteLine(m.Groups["href"].Value);
Console.WriteLine(m.Groups["src"].Value);
} Console.ReadLine();
/*
2.aspx
2.jpg
*/
匹配所有的a标记:(<a href=\")(\\w+[a-zA-Z0-9.-?=/]*)
匹配所有的img标记:(<img src=\")(\\w+[a-zA-Z0-9.-?=/]*)这两个正则合并起来,然后用group的$1 $2来获取好了。