我正在使用HtmlAgilityPack,我希望从类别title
的td中选择值。我需要标签中的值Battlefield 3
。如何选择具有“foo”类的td?
我试过以下,只是为了得到正确的td元素,并且我得到一个异常object is not set to an instance
。
var title = from item in document.DocumentNode.Descendants()
where item.Name == "td" && item.Attributes["class"].Value == "title"
select item.InnerHtml;
有了这个小例子,我可能会弄清楚我需要的其余部分。
谢谢你的建议。
<tr class="first-in-year">
<td class="year">2011</td>
<td class="img"><a href="/battlefield-3/61-27006/"><img src=
"http://media.giantbomb.com/uploads/6/63038/1700748-bf3_thumb.jpg" alt=""></a></td>
<td class="title">
<a href="/battlefield-3/61-27006/">Battlefield 3</a>
<p class="deck">Battlefield 3 is DICE's next installment in the franchise and
will be on PC, PS3 and Xbox 360. The game will feature jets, prone, a
single-player and co-op campaign, and 64-player multiplayer (on PC). It's due out
in Fall of 2011.</p>
</td>
</tr>
在节目的结束,是否缺少撇号或者是故意的吗? – 2011-05-11 22:00:58