【发布时间】:2010-06-12 05:26:19
【问题描述】:
所以我正在编写一个应用程序来进行一点屏幕抓取。我正在使用HTML Agility Pack 将整个HTML 页面加载到一个名为doc 的HtmlDocoument 实例中。现在我想解析那个文档,寻找这个:
<table border="0" cellspacing="3">
<tr><td>First rows stuff</td></tr>
<tr>
<td>
The data I want is in here <br />
and it's seperated by these annoying <br /> 's.
No id's, classes, or even a single <p> tag. </p> Just a bunch of <br /> tags.
</td>
</tr>
</table>
所以我只需要获取第二行中的数据。我怎样才能做到这一点?我应该使用正则表达式还是其他东西?
更新:这是我如何加载我的doc
HtmlWeb hw = new HtmlWeb();
HtmlDocument doc = hw.Load(Url);
【问题讨论】:
-
您的文档中是否只有一个表格?如果没有,您将如何找到您感兴趣的表格?
-
@Mark:基于
cellspacing="3"属性。我知道这听起来 hacky (因为它是),但 1000 多个文档中没有其他表包含 cellspacing 属性。这不是生产代码,只是我正在运行以收集一些数据的项目。 -
您的标题和问题不一致。标题:
How can I get all content within <table></table> tags问题:So I just need to get the data within the 2nd row.这是哪个?你能修复它以使标题和问题匹配吗?
标签: c# screen-scraping html-agility-pack