日期:2014-05-18  浏览次数:20832 次

网站源码截取问题
某论坛的帖子列表源码如下:
<a href="read.php?tid=162061" name="readlink" id="a_ajax_162069" class="subject_t f14">湖光美景[10P]</a>
<a href="read.php?tid=162062" name="readlink" id="a_ajax_162069" class="subject_t f14">湖光美景[10P]</a>
<a href="read.php?tid=162063" name="readlink" id="a_ajax_162069" class="subject_t f14">湖光美景[10P]</a>
<a href="read.php?tid=162064" name="readlink" id="a_ajax_162069" class="subject_t f14">湖光美景[10P]</a>
<a href="read.php?tid=162065" name="readlink" id="a_ajax_162069" class="subject_t f14">湖光美景[10P]</a>
如何才能截取成:
read.php?tid=162061
read.php?tid=162062
read.php?tid=162063
read.php?tid=162064
read.php?tid=162065

正则我不会写,给个源码,

------解决方案--------------------
foreach(Match m in Regex.Mathes(yourhtml,@"(?i)(?<=<a\b[^>]*?href=(['""]?))[^'""]+(?=\1)"))
{
//m.Value就是你想要的
}


------解决方案--------------------
C# code
string[] result=Regex.Mathes(yourhtml,@"(?i)(?<=<a\b[^>]*?href=(['""]?))[^'""]+(?=\1)").Cast<Match>()
.Select(m=>m.Value).Distinct().ToArray();