2016-11-21 64 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); 
} 
相关问题