我需要在Web门户上解析断开的链接(例如404)。它在门户网站上有约10.000页,并包含许多外部链接。我在C#中使用HttpWebRequest下载html页面,然后在html中找到所有链接,并在已选中的组中添加已选中的链接,并在未选中的链接队列中进行检查。我使用multythreading,但是它没有什么好处。 1个线程-每分钟50个链接,5个线程-70。 我认为,我的问题是我获取html代码的方式。我使用简单的HttpWebRequest获取html:
`
string html;
HttpWebResponse response;
StreamReader respStream;
try
{
HttpWebRequest reques = (HttpWebRequest)WebRequest.Create(link.ToString());
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/15.0";
request.Accept = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.AllowAutoRedirect = true;
response = (HttpWebResponse)request.GetResponse();
respStream = new StreamReader(response.GetResponseStream());
html = respStream.ReadToEnd();
response.Close();
respStream.Close();
}
catch (Exception ex)
{
System.Console.WriteLine("-------------\n" +
"Bad link: " + link + "\n" +
"From: " + link.Parent +
"\n" + ex.Message);
link.ErrorComments = ex.Message;
link.Parent.AddSon(link);
continue;
}
normalLinks.Add(link);
`
我的互联网-100mb / s。 1页-150-200 kb。 我需要几次提高速度。有人知道解决方案吗?
答案 0 :(得分:0)
您的许多链接都指向同一个域吗?到同一主机的并发连接数是有限制的。可以在app.config中覆盖它(假设您是.net框架)connection management max connection