<div action-type="feed_list_item" mid="3593380171075233" class="WB_feed_type SW_fun "> <div class="WB_from"> <a class="S_link2 WB_time" target="_blank" title="2013-06-26 10:00" node-type="feed_list_item_date" date="1372212057000" href="/2263807302/zDbfb4vIt">今天 10:00</a><em class="S_txt2">来自</em><a class="S_link2" target="_blank" href="http://app.weibo.com/t/feed/6Lm38l" rel="nofollow">ZAKER</a> <span class="hover"><em class="S_txt3">|</em><a class="S_link2" href="javascript:void(0);" onclick="javascript:window.open('http://service.account.weibo.com/reportspam?rid=3593380171075233&type=1&from=10106&url=&bottomnav=1&wvr=5', 'newwindow', 'height=700, width=550, toolbar =yes, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');" >举报</a></span> </div></div> </div> </div> </div>
string pattern=@"<a[^<]*node-type=\"feed_list_item_date\"[^<]*>.*?</a>";
MatchCollection mch=Regex.Matchs(text,pattern);
foreach(Match m in mch){
string a=m.Value;
}
我只需要取到这个a标签的href属性应该怎么写呢
@Brids:
Regex regex = new Regex("(<a[\\s+]*([^>h]|node-type=\"feed_list_item_date\"[\\s+]*h(?!ref\b))*href[\\s+]*=[\\s+]*[('|\")]?)([^(\\s+|'|\")]*)([^>]*>)",RegexOptions.IgnoreCase);
string url = regex.IsMatch("str") ? regex.Match("str").Groups[2].Value : string.Empty;
str指代你的html url就是你要的连接。
@Brids:
string pattern=@"<a[^<]*node-type=\"feed_list_item_date\"[^<]*>.*?</a>";
string href=@"<a[^<]*href=\"(.*?)\"[^<]*>.*?</a>";
MatchCollection mch=Regex.Matchs(text,pattern);
foreach(Match m in mch){
string url=Regex.Replace(m.Value,href,"$1");
}
在追问一个问题哈,
<div action-type="feed_list_item" mid="3586939628421625" class="WB_feed_type SW_fun "> <div class="WB_screen" style="display:none;"><a class="W_ico12 icon_choose" href=""></a></div> <div class="WB_feed_datail S_line2 clearfix"> <div class="WB_detail"> <div class="WB_text" node-type="feed_list_content" nick-name="勤子要勤奋起来">我是真的怕死了翻译这种全文都是由短句组成的文章。。。确定逻辑关系、变换不同的句式,还要斟酌用词,完全是举步维艰!!一篇下来脑细胞死了一半不说,好不容易建立起来的自信也瞬间土崩瓦解!!</div> <div class="WB_func clearfix"> <div class="WB_handle"> <a href="javascript:void(0);" action-type="feed_list_like" action-data="version=mini&qid=heart&mid=3586939628421625&like_src=1" title="赞" ><em class="W_ico20 icon_praised_b"></em></a><i class="S_txt3">|</i> <a action-data="allowForward=1&url=http://weibo.com/2263807302/zAtHczkQF&mid=3586939628421625&name=勤子要勤奋起来&uid=2263807302&domain=2263807302" action-type="feed_list_forward" href="javascript:void(0);">转发</a><em class="S_txt3">|</em> <a action-type="feed_list_favorite" diss-data="fuid=2263807302" href="javascript:void(0);">收藏</a><em class="S_txt3">|</em> <a action-type="feed_list_comment" action-data="location=profile" href="javascript:void(0);">评论</a> <!-- <em class="S_txt3">|</em> <a href="javascript:void(0);" action-type="feed_list_more_option" action-data="addTag=&report=javascript:window.open('http://service.account.weibo.com/reportspam?rid=3586939628421625&type=1&url=&bottomnav=1&wvr=5', 'newwindow', 'height=700, width=550, toolbar =yes, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');&taglist=">更多<span class="W_arrow"><em class="down">◆</em></span></a> --> </div> <div class="WB_from"> <a class="S_link2 WB_time" target="_blank" title="2013-06-08 15:28" node-type="feed_list_item_date" date="1370676512000" href="/2263807302/zAtHczkQF">6月8日 15:28</a><em class="S_txt2">来自</em><a class="S_link2" target="_blank" href="http://app.weibo.com/t/feed/6Lm38l" rel="nofollow">ZAKER</a> <span class="hover"><em class="S_txt3">|</em><a class="S_link2" href="javascript:void(0);" onclick="javascript:window.open('http://service.account.weibo.com/reportspam?rid=3586939628421625&type=1&from=10106&url=&bottomnav=1&wvr=5', 'newwindow', 'height=700, width=550, toolbar =yes, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');" >举报</a></span> </div></div> <div node-type="feed_list_repeat" class="WB_media_expand repeat S_line1 S_bg4" style="display:none;"></div> </div> </div> </div> <div action-type="feed_list_item" mid="3586639018350815" class="WB_feed_type SW_fun "> <div class="WB_screen" style="display:none;"><a class="W_ico12 icon_choose" href=""></a></div> <div class="WB_feed_datail S_line2 clearfix"> <div class="WB_detail"> <div class="WB_text" node-type="feed_list_content" nick-name="勤子要勤奋起来">有一种青春叫高考〜不管多久,说起高考的点点滴滴总忍不住一种眼眶湿润的感动!加油〜 【 女生考场内昏迷 男生抱其找警察 <a title="http://iphone.myzaker.com/l.php?l=51b1672d7f52e94515002ab4" href="http://t.cn/zHOnr5j" target="_blank" mt="url" action-type="feed_list_url">http://t.cn/zHOnr5j</a> 】(分享自 ZAKER)</div> <!-- 引用文件时,必须对midia_info赋值 --><!-- 微博心情,独立于标准的ul节点 --> <ul class="WB_media_list clearfix" node-type="feed_list_media_prev"> <li> <!-- img之间不能加空格 --> <div class="chePicMin S_bg2 bigcursor" action-type="feed_list_media_img" action-data="uid=2263807302&mid=3586639018350815" suda-data="key=feed_image_click&value=image_zoomin"><img class="bigcursor" node-type="feed_list_media_bgimg" src="http://ww4.sinaimg.cn/thumbnail/86eef546jw1e5fswudgwuj20hs2ywn6d.jpg" alt=""/><img style="left: 39.5px; top: 52px; display: none;" src="http://img.t.sinajs.cn/t5/style/images/common/loading.gif" class="loading_gif"></div> </li> </ul> <div class="WB_media_expand SW_fun2 S_line1 S_bg1" style="display: none;" node-type="feed_list_media_disp"></div> <div class="WB_func clearfix"> <div class="WB_handle"> <a href="javascript:void(0);" action-type="feed_list_like" action-data="version=mini&qid=heart&mid=3586639018350815&like_src=1" title="赞" ><em class="W_ico20 icon_praised_b"></em></a><i class="S_txt3">|</i> <a action-data="allowForward=1&url=http://weibo.com/2263807302/zAlSlz2qz&mid=3586639018350815&name=勤子要勤奋起来&uid=2263807302&domain=2263807302&pid=86eef546jw1e5fswudgwuj20hs2ywn6d" action-type="feed_list_forward" href="javascript:void(0);">转发</a><em class="S_txt3">|</em> <a action-type="feed_list_favorite" diss-data="fuid=2263807302" href="javascript:void(0);">收藏</a><em class="S_txt3">|</em> <a action-type="feed_list_comment" action-data="location=profile" href="javascript:void(0);">评论</a> <!-- <em class="S_txt3">|</em> <a href="javascript:void(0);" action-type="feed_list_more_option" action-data="addTag=&report=javascript:window.open('http://service.account.weibo.com/reportspam?rid=3586639018350815&type=1&url=&bottomnav=1&wvr=5', 'newwindow', 'height=700, width=550, toolbar =yes, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');&taglist=">更多<span class="W_arrow"><em class="down">◆</em></span></a> --> </div>
有没有可能用一个正则同时把这个div里面的mid="3586939628421625" ,和node-type="feed_list_item_date" date="1370676512000" href="/2263807302/zAtHczkQF"这段中的href属性取到,忘各位大侠指点
@Brids:
node-type="feed_list_item_date" date="1370676512000" 是在那些标签的
<a> 与 <div> 的层次关系是怎样的
好晕,