0
我正在從一個網站獲取表信息的小程序,稍後將按DateTime對這些信息進行排序。使用HTML敏捷包從網站獲取多個表並將它們添加到列表
我最大的問題是,我的函數獲取網站並將其變成一個字符串後,我找不到一種方法將信息獲取到列表中。我不斷收到NullPointer錯誤。
我嘗試這樣做:
WebClient webClient = new WebClient();
string page = webClient.DownloadString("http://www.mufap.com.pk/payout-
report.php?tab=01");
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(page);
List<List<string>> table =
doc.DocumentNode.SelectSingleNode("//table[@class='1']")
.Descendants("tr")
.Skip(1)
.Where(tr=>tr.Elements("td").Count()>1)
.Select(tr => tr.Elements("td")
.Select(td => td.InnerText.Trim()).ToList())
.ToList();
但由於某些原因,我不斷收到此錯誤:
An unhandled exception of type 'System.NullReferenceException' occurred in WebGetter.exe
我覺得這與我選擇的課上做,雖然表的類命名爲「1」,所以這應該有正確的參考。當我使用
我不斷收到這樣的:
System.Collections.Generic.List1[System.Collections.Generic.List1[System.String]]
如果你可以點我到正確的方向,這將是很好的。
忘了提,這是我使用的鏈接: https://www.athletic.net/TrackAndField/Division/Top.aspx?DivID=81830 –
在給定的網址中沒有任何含'1'類的表 –
@RubenVardanyan那麼我該如何獲得第一個表?我對此很新穎:s –