0

我有一个包含许多<tr>标签的 HTML 文档。我想查看一个特定的表,并在每个表中创建一组 id 标签<tr>。每个<tr>' 具有相同的类值。例如:

...
<table>
<tr class="blah" id="234">...</tr>
<tr class="blah" id="435">...</tr>
...</table>

在 HTMLDocument 中,我使用以下方法创建了一个 HTMLElementCollection:

document.GetElementsByTagName("tr")

我认为从那里做的合乎逻辑的事情是遍历每一行并使用沿线的东西

row.GetAttribute("class") 

或者

row.GetAttribute("id")

但是,这两个都返回一个空白字符串。我可以看到outterHTML元素的属性说“<tr class="blahblah" id="435345"><td>...

outterHTML除了必须剖析属性的字符串之外,还有什么建议吗?

4

1 回答 1

0

I finally figured out what the problem was. When running row.GetAttribute(), I had the wrong property in there. While the HTML looked like this:

<tr class="blah">

The C# code should look like this:

row.GetAttribute("className");

And it turns out that the reason only half of the <tr> tags showed up was because the page does a full load unpopulated, then refreshes itself fully populated with the rest of the <tr> tags in place.

于 2013-05-02T13:49:17.650 回答