Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试从HTML页面提取标记_C#_Xpath_Html Agility Pack - Fatal编程技术网

C# 尝试从HTML页面提取标记

C# 尝试从HTML页面提取标记,c#,xpath,html-agility-pack,C#,Xpath,Html Agility Pack,我需要找到一个HTML页面的所有节点,这些节点都有一个结构,…对确定节点的开始和结束。我试图找到这样的节点: 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.SelectNo

我需要找到一个HTML页面的所有节点,这些节点都有一个结构
对确定节点的开始和结束。我试图找到这样的节点:

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()
所显示的一切都不是它想要显示的,包括
北部和西部大部分是平坦的平原或平缓起伏的丘陵。



我做错了什么?

请显示输入示例,而不是描述输入。小提示:您也可以在XPath中使用单引号,例如
@class='mw headline'
——无需转义双引号。不清楚您试图检索的内容,但当您可以使用InnerHtml、InnerText或OriginalName时,是否有理由使用Line和LinePosition来获取子字符串?