C# 通过HtmlAlityPack从表中获取链接
我有一个简单的html表格:C# 通过HtmlAlityPack从表中获取链接,c#,html,parsing,html-parsing,html-agility-pack,C#,Html,Parsing,Html Parsing,Html Agility Pack,我有一个简单的html表格: <table> <tr> <td> <a href="http://someurl_1.com">item name1</a> </td> <td> Value 1 </td> </tr> <tr> <td> <a href="http://s
<table>
<tr>
<td>
<a href="http://someurl_1.com">item name1</a>
</td>
<td>
Value 1
</td>
</tr>
<tr>
<td>
<a href="http://someurl_2.com">item name2</a>
</td>
<td>
Value 2
</td>
</tr>
</table>
但我在那个数组中没有url
如何将其转换为表值,因此在结果中,我需要:
table[0][0] -> http://someurl_1.com
table[0][1] -> item name1
table[0][2] -> value 1
table[1][0]-> http://someurl_2.com
table[1][1] -> item name2
table[1][2] -> value 2
任何帮助,谢谢!谢谢我建议对每个单元格使用xpath,并将它们的数据映射到数组中 例如,第二项的xpath是/html/body/table/tbody/tr[2]/td[1]/a
var doc=new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(htmlText);
var nodes=doc.DocumentNode.SelectNodes(“/html/body/table/tbody/tr[2]/td[1]/a”);
将为您提供
作为节点,您可以使用该节点进一步获取url或文本
table[0][0] -> item name1
table[0][1] -> value 1
table[1][0] -> item name2
table[1][1] -> value 2
table[0][0] -> http://someurl_1.com
table[0][1] -> item name1
table[0][2] -> value 1
table[1][0]-> http://someurl_2.com
table[1][1] -> item name2
table[1][2] -> value 2