求个正则 提取如下HTML的a标签

lijing3333 2012-06-18 01:43:07

<li class="list-item"> <h3 class="summary"><a title="夏装新款 2012时尚休闲 韩版宽松大码 条纹拼接 女士短袖T恤衫 潮" class="EventCanSelect" target="_blank" href="http://item.taobao.com/item.htm?id=17859128415" stat="lf_aclog=1-17859128415-40-all|-0-23.10&lf_acfrom=0&at_alitrackid=&stats_click=compass%3A4%3Buser_group%3A--%3Bscreen_size%3A0%3Bsearch_cfg%3A2&rn=52718bed979ec1c7a18ccede7680b65c">夏装新款 2012时尚休闲 韩版宽松大码 条纹拼接 <span class="H">女</span>士短袖<span class="H">T恤</span>衫 潮 </a></h3><div class="photo">
<a target="_blank" href="http://item.taobao.com/item.htm?id=17859128415" stat="lf_aclog=1-17859128415-40-all|-0-23.10&lf_acfrom=0&at_alitrackid=&stats_click=compass%3A4%3Buser_group%3A--%3Bscreen_size%3A0%3Bsearch_cfg%3A2&rn=52718bed979ec1c7a18ccede7680b65c"><span><img alt="" src="http://img01.taobaocdn.com/bao/uploaded/i1/T1EAa.XhduXXXPQgc2_043850.jpg_160x160.jpg"></span></a> <a title="举报该宝贝" target="_blank" href="http://support.taobao.com/myservice/suit/accuse_punish.jhtml?Query=t%D0%F4+%C5%AE&BucketID=20&auction_num_id=17859128415&fromSource=search&Category=0&sort=all&display_type=3" class="antispam">举报</a></div> <ul class="attribute"> <li class="price"><em>23.10</em> <span>最近成交4笔</span></li> <li class="shipment">
<span class="fee">运费:12.00</span> <span class="loc">广东 揭阳</span></li> <li class="seller"><a target="_blank" href="http://store.taobao.com/shop/view_shop.htm?user_number_id=890090071">2012_魅丽百度</a>
<span data-icon="small" data-item="17859128415" data-display="inline" data-nick="2012_%E9%AD%85%E4%B8%BD%E7%99%BE%E5%BA%A6" data-encode="true" class="ww-light ww-small"><a target="_blank" href="http://www.taobao.com/webww/?ver=1&&touid=cntaobao2012_%E9%AD%85%E4%B8%BD%E7%99%BE%E5%BA%A6&siteid=cntaobao&status=2&portalId=&gid=17859128415&itemsId=" class="ww-inline ww-online" title="点此可以直接和卖家交流选好的宝贝,或相互交流网购体验,还支持语音视频噢。"><span>旺旺在线</span></a></span>

</li> <li dataurl="/interfaces/shopinfo_proxy.php?sid=890090071&pf=12.00&bid=17859128415&a_tag=&credit_rate=10000" class="shopinfo"></li> </ul>
<div class="legend2"><a href="http://www.taobao.com/go/act/315/xfzbz_rsms.php" class="xb-as-fact" title="卖家承诺消费者保障服务" target="_blank"><span>消费者保障</span></a>
</div>

</li>

上面是淘宝商品list页面 商品html 我想提取商品详情的url
我想提取
<div class="photo"> 里面 那个a标签的 url链接地址 不知道正则是怎么写的。

求教了!!!

就是这个
http://item.taobao.com/item.htm?id=17859128415

可以提取出来吗??
...全文
251 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hank180 2012-06-19
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

引用 3 楼 的回复:

引用 1 楼 的回复:
(?is)<div\sclass=(['"]?)photo\1>.*?<a\b[^>]*?href=(['"]?)(?<url>[^'"]+)\2[^>]*?>

取Group["url"].Value


MatchCollection matches = Regex.Matches(htmlStr, "(?is)<div\……
[/Quote]

q107770540 2012-06-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

引用 1 楼 的回复:
(?is)<div\sclass=(['"]?)photo\1>.*?<a\b[^>]*?href=(['"]?)(?<url>[^'"]+)\2[^>]*?>

取Group["url"].Value


MatchCollection matches = Regex.Matches(htmlStr, "(?is)<div\sclass=(['"]?)……
[/Quote]
双引号要转义
EnForGrass 2012-06-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

引用 1 楼 的回复:
(?is)<div\sclass=(['"]?)photo\1>.*?<a\b[^>]*?href=(['"]?)(?<url>[^'"]+)\2[^>]*?>

取Group["url"].Value


MatchCollection matches = Regex.Matches(htmlStr, "(?is)<div\sclass=(['"]?)……
[/Quote]

MatchCollection matches = Regex.Matches(htmlStr, @"(?is)<div\sclass=(['""]?)photo\1>.*?<a\b[^>]*?href=(['""]?)(?<url>[^'""]+)\2[^>]*?>");
string ahtml = "";
foreach (Match match in matches)
{
ahtml += match.Groups["url"].Value + "\r\n";
}
EnForGrass 2012-06-18
  • 打赏
  • 举报
回复
(?is)<div\b[^>]*?class="photo">[^>]*?<a\b[^>]*?href=(["'\s]?)([^"']*?)\1[^>]*?>
取第二个分组,Groups[2].Value
lijing3333 2012-06-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
(?is)<div\sclass=(['"]?)photo\1>.*?<a\b[^>]*?href=(['"]?)(?<url>[^'"]+)\2[^>]*?>

取Group["url"].Value
[/Quote]

MatchCollection matches = Regex.Matches(htmlStr, "(?is)<div\sclass=(['"]?)photo\1>.*?<a\b[^>]*?href=(['"]?)(?<url>[^'"]+)\2[^>]*?>");
string ahtml = "";
foreach (Match match in matches)
{
ahtml += match.Groups["url"].Value + "\r\n";
}

取不出来啊 报错了。。。。
天下如山 2012-06-18
  • 打赏
  • 举报
回复
楼上先进啊
我还想说 直接用jquery获取href的内容呢。
q107770540 2012-06-18
  • 打赏
  • 举报
回复
(?is)<div\sclass=(['"]?)photo\1>.*?<a\b[^>]*?href=(['"]?)(?<url>[^'"]+)\2[^>]*?>

取Group["url"].Value

62,072

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧