私はdiv、スパン、ラベルなどを基本的に特定の属性を持つ任意の要素を選択しようとしています。
IEnumerable<HtmlNode> allDivsWithItemType = _doc.DocumentNode.Descendants("div").Where(d => d.Attributes.Contains("itemtype"));
すべての子孫を上記のようなものに縄を張る方法はありますか?上記はdivを明示的に見つけるためです。私は重複するコードが1つの単語を置き換えるために余分な行を追加するのを避けようとしています。
例として(機能しない)
IEnumerable<HtmlNode> allDivsWithItemType = _doc.DocumentNode.Descendants("*").Where(d => d.Attributes.Contains("itemtype"));
試してください:
IEnumerable<HtmlNode> allDivsWithItemType = _doc.DocumentNode.Descendants()
.Where(d => d.Attributes.Contains("itemtype"));