2016-11-21 68 views
3
for (int x = 0; x < 50; x++) 
{ 
    NSoupClient.Connect("https://steamcommunity.com/gid/" + x) 
       .UserAgent("Firefox") 
       .Timeout(10000) 
       .Get(); 
} 

這段代碼會拋出我這個錯誤(當int是5它總是停):C#System.NullReferenceException NSoup

未處理的類型爲「System.NullReferenceException」發生異常NSoup.dll

enter image description here

+1

的【什麼是一個NullReferenceException,如何解決呢?(可能的複製http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-我修復它) – mybirthname

+0

我以前見過這個,但什麼是空? – nooby

回答

0

我使用WebClient修復了這個問題以下載頁面。

using (WebClient wc = new WebClient()) 
{ 
    wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows; Windows NT 5.1; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4"); 
    string html = wc.DownloadString(url); 
    Document document = NSoupClient.Parse(html); 
} 
相關問題