对于此示例,如何使用 htmlagilitypack 从 HTML 中提取文本?
我想从 HTML 源中提取文本。我正在尝试使用 c# 和 htmlagilitypack dll。
来源是:
<table>
<tr>
<td class="title">
<a onclick="func1">Here 2</a>
</td>
<td class="arrow">
<img src="src1" width="9" height="8" alt="Down">
</td>
<td class="percent">
<span>39%</span>
</td>
<td class="title">
<a onclick="func2">Here 1</a>
</td>
<td class="arrow">
<img src="func3" width="9" height="8" alt="Up">
</td>
<td class="percent">
<span>263%</span>
</td>
</tr>
</table>
How can I get the text Here 1 and Here 2 from the table?
I wanna extract the text from a HTML source. I'm trying with c# and htmlagilitypack dll.
The source is:
<table>
<tr>
<td class="title">
<a onclick="func1">Here 2</a>
</td>
<td class="arrow">
<img src="src1" width="9" height="8" alt="Down">
</td>
<td class="percent">
<span>39%</span>
</td>
<td class="title">
<a onclick="func2">Here 1</a>
</td>
<td class="arrow">
<img src="func3" width="9" height="8" alt="Up">
</td>
<td class="percent">
<span>263%</span>
</td>
</tr>
</table>
How can I get the text Here 1 and Here 2 from the table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不太漂亮但应该可以
not so pretty but should work
Xpath 版本
和 LINQ 版本只需更改 var Nodes = .. 行:
Xpath version
and for the LINQ version just change the var Nodes = .. line with: