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 –