如果用过 迅雷的话 右键 全部链接 不知道他是怎么做到的 ?
就是怎么分析出来他的 所有 链接网站的 我们能用C#实现吗?
那位有经验 给点见意?MatchCollection matches = Regex.Matches(this.HTML, "http://(\\S+[^ <^>])\""); this.HTML=一个网站的源代码文本文件。
就是怎么分析出来他的 所有 链接网站的 我们能用C#实现吗?
那位有经验 给点见意?MatchCollection matches = Regex.Matches(this.HTML, "http://(\\S+[^ <^>])\""); this.HTML=一个网站的源代码文本文件。
{
List<string> lstReturn = new List<string>();
string strContent = html; string strPattern = "<a .*?href.*?>(?<link>.*?)</a>";
Regex r = new Regex(strPattern, RegexOptions.Multiline | RegexOptions.IgnoreCase); MatchCollection mc = r.Matches(strContent);
foreach (Match m in mc)
{
lstReturn.Add(m.Value);
}
return lstReturn;
}
有点错 list
Count = 19
[0]: "<a onclick=s(this) href=http://news.baidu.com>新 闻</a>"
[1]: "<a onclick=s(this) href=http://tieba.baidu.com>贴 吧</a>"
[2]: "<a onclick=s(this) href=http://zhidao.baidu.com>知 道</a>"
[3]: "<a onclick=s(this) href=http://mp3.baidu.com>MP3</a>"
[4]: "<a onclick=s(this) href=http://image.baidu.com>图 片</a>"
[5]: "<a onclick=s(this) href=http://video.baidu.com>视 频</a>"
[6]: "<a href=\"http://passport.baidu.com/?login&tpl=mn&u='+escape(location.href)+'\">登录</a>"
[7]: "<a href=/search/jiqiao.html>帮助</a>"
[8]: "<a href=/gaoji/advanced.html>高级</a>"
[9]: "<a href=http://hi.baidu.com>空间</a>"
[10]: "<a href=\"http://www.hao123.com\" onmousedown=\"(new Image()).src='http://s.baidu.com/w.gif?fm=index&title=hao123&t='+(new Date().getTime())\">hao123</a>"
[11]: "<a href=/more/ style=\"font-family:宋体\">更多>></a>"
[12]: "<a onClick=\"this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.baidu.com')\" href=http://utility.baidu.com/traf/click.php?id=215&url=http://www.baidu.com>把百度设为首页</a>"
[13]: "<a href=http://jingjia.baidu.com>企业推广</a>"
[14]: "<a href=http://top.baidu.com>搜索风云榜</a>"
[15]: "<a href=/home.html>关于百度</a>"
[16]: "<a href=http://ir.baidu.com>About Baidu</a>"
[17]: "<a href=http://www.baidu.com/duty/>使用百度前必读</a>"
[18]: "<a href=http://www.miibeian.gov.cn target=_blank>京ICP证030173号</a>"
{
List<string> lstReturn = new List<string>();
string strContent = html;
strContent = strContent.Replace("\n", "");
strContent = strContent.Replace("\r", "");
strContent = strContent.Replace("\t", ""); string strPattern = @"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?";
Regex r = new Regex(strPattern, RegexOptions.Multiline | RegexOptions.IgnoreCase); MatchCollection mc = r.Matches(strContent);
foreach (Match m in mc)
{
lstReturn.Add(m.Value);
}
return lstReturn;
} private void button1_Click_1(object sender, EventArgs e)
{
List<string> lst= GetHtmlAllLink(richTextBox1.Text);
listBox1.DataSource =lst;
listBox1.Refresh();
}