【发布时间】:2017-10-04 14:19:23
【问题描述】:
我正在开发一个从网站获取表格信息的小程序,稍后将按日期时间对这些信息进行排序。
我最大的问题是,在我获取网站并将其转换为字符串的函数之后,我找不到将信息放入列表的方法。我不断收到 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]]
如果你能指出我正确的方向,那就太好了。
【问题讨论】:
-
忘了说这是我正在使用的链接:athletic.net/TrackAndField/Division/Top.aspx?DivID=81830
-
在你给定的url中没有
1类的表 -
@RubenVardanyan 那么我如何获得第一张桌子呢?我对此很陌生:s
-
所以你是指你写
class=1时的第一个表格元素? @科林
标签: c# html html-table html-agility-pack