簡體   English   中英

C#System.NullReferenceException NSoup

[英]C# System.NullReferenceException NSoup

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”類型異常

在此輸入圖像描述

似乎你不是唯一有問題的人 - https://nsoup.codeplex.com/workitem/8

似乎是圖書館本身的一個問題。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM