1

我需要找到具有结构的 HTML 页面的所有节点<h2><span class="mw-headline" ...> ... </span></h2><h2>...<\h2>对确定节点的开头和结尾。我试图找到这样的节点:

string raw_code = doc.DocumentNode.SelectNodes("/")[0].WriteTo(); // can there be more than 1 node there?
string[] lines = raw_code.Split('\n'); 
foreach(HtmlNode hdr in doc.DocumentNode.SelectNodes("//span[@class = \"mw-headline\"]"))
{
  int line_number = hdr.Line;
  int line_position = hdr.LinePosition;
  string font_tag = lines[line_number].Substring(line_position - font_tag_length, line_position);
  MessageBox.Show(lines[line_number]); // returns div c
}

坦率地说,它MessageBox.Show()显示了任何东西,但它并不是要显示的,包括<div class="thumb tright">and <p>Mostly flat plains or gently rolling hills in north and west.</p>
我做错了什么?

4

0 回答 0