【发布时间】:2015-11-21 18:15:43
【问题描述】:
我通过 html 获取 html 表单用户。获得 html 后,我通过 HtmlDocument.LoadHtml() 函数将其加载到 htmlaglity 中。这是html代码:
<table>
<tr>
<td>Some text</td>
</tr>
</table>
这里是c#代码:
HtmlDocument hd = new HtmlDocument();
hd.LoadHtml(html);
string st_debug;
foreach (var item in hd.DocumentNode.Descendants("tr"))
{
foreach (HtmlNode secNode in item.ChildNodes)
{
st_debug = secNode.InnerHtml;
}
}
问题是它返回给我的数据是“”而不是“sometext”,当我删除标签之间的额外空格时:
<table>
<tr>
<td>
Some text
</td>
</tr>
<table>
它给了我正确的输出。解决方案是什么,因为用户只会复制 html 并按原样过去。 我已经在 winform 中编写了相同的代码,但是从浏览器控件中获取了 html,并且效果很好。加载html时有什么问题吗?请帮忙
【问题讨论】:
标签: asp.net-mvc html-agility-pack