【问题标题】:C# System.NullReferenceException NSoupC# System.NullReferenceException NSoup
【发布时间】:2017-04-04 11:33:03
【问题描述】:
for (int x = 0; x < 50; x++)
{
    NSoupClient.Connect("https://steamcommunity.com/gid/" + x)
               .UserAgent("Firefox")
               .Timeout(10000)
               .Get();
}

这段代码会给我这个错误(并且它总是在 int 为 5 时停止):

NSoup.dll 中出现“System.NullReferenceException”类型的未处理异常

【问题讨论】:

标签: c# jsoup html-parsing


【解决方案1】:

我使用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);
}

【讨论】:

    猜你喜欢
    • 2015-11-17
    • 1970-01-01
    • 2014-01-26
    • 2018-09-03
    • 2014-03-07
    • 1970-01-01
    • 1970-01-01
    • 2013-04-29
    • 2013-09-04
    相关资源
    最近更新 更多