网站内链接分析问题

hylgogogo_2009 2010-09-25 02:46:40
如何获取网站的所有站内链接,并分析链接是否通过?

包括网站的所有页面
请教高手。。。
...全文
169 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hylgogogo_2009 2010-09-25
  • 打赏
  • 举报
回复
呵呵 谢谢 没做过这方面的程序
symbol_bc 2010-09-25
  • 打赏
  • 举报
回复

Regex reg = new Regex(@"(?is)<a[^>]+>(?><a(?<o>)(?<p>)|</a>(?<-o>)|((?!</?a).)*)*(?(o)(?!))(?(p)|(?!))</a>");
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
string url = m.Groups["url"].Value;
SendRequest(url);
}


//楼主不应该什么都问,这样不利于自己成长。
hylgogogo_2009 2010-09-25
  • 打赏
  • 举报
回复
链接我都取出来了,也分析好了,也存到队列中了,但是如何循环分析队列中的链接数据呢 ?
hylgogogo_2009 2010-09-25
  • 打赏
  • 举报
回复
谢谢,我去试试。。。
symbol_bc 2010-09-25
  • 打赏
  • 举报
回复

HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://www.contoso.com");
httpReq.AllowAutoRedirect = false;

HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse();

if (httpRes.StatusCode==HttpStatusCode.OK)
{
// 根据HttpStatusCode对照判断当前链接是否用

//读出数据
System.IO.StreamReader sr = new System.IO.StreamReader(httpRes.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));

string HTML = sr.ReadToEnd();

//取出所有链接
Regex reg = new Regex(@"(?is)<a[^>]+>(?><a(?<o>)(?<p>)|</a>(?<-o>)|((?!</?a).)*)*(?(o)(?!))(?(p)|(?!))</a>");
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
SendRequest(m.Value);
}

// Close the response.
httpRes.Close();




代码大致如此
hylgogogo_2009 2010-09-25
  • 打赏
  • 举报
回复
差不多,但是现在不知道如何去做,有例子观摩下吗?
symbol_bc 2010-09-25
  • 打赏
  • 举报
回复
跟蜘蛛差不多吧,从后台发请求,下载页面后,用正则分析,取链接地址,向地址发送请求,取返回的httpstate。

13,347

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET技术前瞻
社区管理员
  • .NET技术前瞻社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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