2012-09-11 1 views
0

이 코드가 있습니다)메신저 URL에 WebException이 생기는 이유는 무엇입니까?

private List<string> webCrawler(string url, int levels) 
     { 
      HtmlAgilityPack.HtmlDocument doc; 
      HtmlWeb hw = new HtmlWeb(); 
      List<string> webSites; 
      List<string> csFiles = new List<string>(); 

      csFiles.Add("temp string to know that something is happening in level = " + levels.ToString()); 
      csFiles.Add("current site name in this level is : "+url); 

      doc = hw.Load(url); 
      webSites = getLinks(doc); 


      if (levels == 0) 
      { 
       return csFiles; 
      } 
      else 
      { 
       int actual_sites = 0; 
       for (int i = 0; i < webSites.Count() && i< 20; i++)     { 
        string t = webSites[i]; 
             if ((t.StartsWith("http://")==true) || (t.StartsWith("https://")==true))      { 
         actual_sites++; 
         csFiles.AddRange(webCrawler(t, levels - 1)); 
         Texts(richTextBox1, "Level Number " + levels + " " + t + Environment.NewLine, Color.Red); 
        } 
       } 

       return csFiles; 
      } 


     } 

그리고 getLinks은 (이다

private List<string> getLinks(HtmlAgilityPack.HtmlDocument document) 
     { 

      List<string> mainLinks = new List<string>(); 
      var linkNodes = document.DocumentNode.SelectNodes("//a[@href]"); 
      if (linkNodes != null) 
      { 
       foreach (HtmlNode link in linkNodes) 
       { 
        var href = link.Attributes["href"].Value; 
        mainLinks.Add(href); 
       } 
      } 
      return mainLinks; 

     } 

문제는, 예를 들면 몇 시간 후에는이 사이트에 점점 내가 google.com으로 기어 :

01 :

http://picasa.google.co.il/intl/iw/#utm_source=iw-all-more&amp;utm_campaign=iw-pic&amp;utm_medium=et

은 그 다음 줄에 예외를 받고 메신저 23,516,

doc = hw.Load(url); 

오류 : 원격 이름을 확인할 수 없습니다 : 'picasa.google.co.il'

예외가이다 :

System.Net.WebException was unhandled 
    Message=The remote name could not be resolved: 'picasa.google.co.il' 
    Source=System 
    StackTrace: 
     at System.Net.HttpWebRequest.GetResponse() 
     at HtmlAgilityPack.HtmlWeb.Get(Uri uri, String method, String path, HtmlDocument doc, IWebProxy proxy, ICredentials creds) in C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs:line 1446 
     at HtmlAgilityPack.HtmlWeb.LoadUrl(Uri uri, String method, WebProxy proxy, NetworkCredential creds) in C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs:line 1563 
     at HtmlAgilityPack.HtmlWeb.Load(String url, String method) in C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs:line 1152 
     at HtmlAgilityPack.HtmlWeb.Load(String url) in C:\Source\htmlagilitypack\Trunk\HtmlAgilityPack\HtmlWeb.cs:line 1107 
     at GatherLinks.Form1.webCrawler(String url, Int32 levels) in D:\C-Sharp\GatherLinks\GatherLinks\GatherLinks\Form1.cs:line 79 
     at GatherLinks.Form1.webCrawler(String url, Int32 levels) in D:\C-Sharp\GatherLinks\GatherLinks\GatherLinks\Form1.cs:line 108 
     at GatherLinks.Form1.webCrawler(String url, Int32 levels) in D:\C-Sharp\GatherLinks\GatherLinks\GatherLinks\Form1.cs:line 108 
     at GatherLinks.Form1..ctor() in D:\C-Sharp\GatherLinks\GatherLinks\GatherLinks\Form1.cs:line 31 
     at GatherLinks.Program.Main() in D:\C-Sharp\GatherLinks\GatherLinks\GatherLinks\Program.cs:line 18 
     at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) 
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: 

어떻게/수정/해결을 복구 할 수 있습니다 ?

감사합니다.

+3

Windows 명령 프롬프트를 열고 'ping picasa.google.co.il'을 입력 해보십시오. 그럼 왜 깨닫게 될거야. – Adam

+0

'Message = 원격 이름을 확인할 수 없습니다 : 'picasa.google.co.il'' 그 자체로 설명이 간단합니다. – Icarus

+0

codesparkle 및 icarus true 이제 사이트가 존재하지 않습니다. 그런 경우를 처리하기 위해 시도하고 잡아야합니까? –

답변

3

예외는 picasa.google.co.il을 IP 주소로 확인할 수 없다는 것을 알려줍니다. 이름이 정확한지 확인하기 만하면됩니다.

명령 창을 열고 유형 :

ping picasa.google.co.il 

당신은 그것을위한 DNS 항목이 없기 때문에 컴퓨터가이 서버와 통신 할 수 있음을 확인할 수 있습니다.

+0

Davisoa 바로 지금이 사이트가 존재하지 않는다는 것을 알았습니다. 이 문제를 처리하고 행을 캐치하는 가장 좋은 방법은 무엇입니까? doc = hw.Load (url); ? –

+0

예, 나는'Load' 호출에서'try ... catch (WebException wex)'를 넣을 것입니다. – davisoa

관련 문제