嗨,我在我的网络应用程序中构建了一个简单的基于线程池的网络爬虫。它的工作是爬取自己的应用程序空间,并为每个有效网页及其元内容构建一个 Lucene 索引。这就是问题所在。当我从 Visual Studio Express 的调试服务器实例运行爬虫并提供起始实例作为 IIS url 时,它工作正常。但是,当我不提供 IIS 实例并且它需要自己的 url 来启动爬网过程(即爬网自己的域空间)时,我会受到 Webresponse 语句上的操作超时异常的打击。有人可以指导我在这里应该或不应该做什么吗?这是我获取页面的代码。它在多线程环境中执行。
private static string GetWebText(string url)
{
string htmlText = "";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.UserAgent = "My Crawler";
using (WebResponse response = request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
htmlText = reader.ReadToEnd();
}
}
}
return htmlText;
}
以下是我的堆栈跟踪:
at System.Net.HttpWebRequest.GetResponse()
at CSharpCrawler.Crawler.GetWebText(String url) in c:\myAppDev\myApp\site\App_Code\CrawlerLibs\Crawler.cs:line 366
at CSharpCrawler.Crawler.CrawlPage(String url, List`1 threadCityList) in c:\myAppDev\myApp\site\App_Code\CrawlerLibs\Crawler.cs:line 105
at CSharpCrawler.Crawler.CrawlSiteBuildIndex(String hostUrl, String urlToBeginSearchFrom, List`1 threadCityList) in c:\myAppDev\myApp\site\App_Code\CrawlerLibs\Crawler.cs:line 89
at crawler_Default.threadedCrawlSiteBuildIndex(Object threadedCrawlerObj) in c:\myAppDev\myApp\site\crawler\Default.aspx.cs:line 108
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
谢谢和欢呼,莱昂。