[英]XmlNode xml xpath
I have myself a small C# console application that uses the System.Xml
namespace as well as the HTMLAgilityPack
library, my program is trying to scrape product variant information from a specific webpage, but I face an unusual issue. 我自己有一个使用
System.Xml
命名空间以及HTMLAgilityPack
库的小型C#控制台应用程序,我的程序试图从特定网页上抓取产品变体信息,但我遇到了一个不寻常的问题。 My program appears to be skipping over a certain HTML tag? 我的程序似乎跳过了某个HTML标签?
Here is the HTML code that I am pulling down 这是我要下拉的HTML代码
<option value="0">Select a size</option>
<option value="5">686 x 1981mm, 35mm Thick: £143.01</option>
<option value="7">762 x 1981mm, 35mm Thick: £143.01</option>
<option value="9">838 x 1981mm, 35mm Thick: £143.01</option>
Here is my code for parsing the above HTML 这是我解析上述HTML的代码
if (vars != null && vars.Count > 0)
{
int loc = 1;
foreach (XmlNode item in vars)
{
// Get the <option> ... </option> contents
string name = item.SelectSingleNode(string.Format("//option[{0}]", loc)).GetInnerTextFromNode();
string value = item.SelectSingleNode(string.Format("//option[{0}]", loc)).GetAttributeFromNode("value");
loc++;
}
}
For some reason my code is skipping over the second tag so I end up with 3 results instead of 4, ignoring it as if it does not exist. 由于某种原因,我的代码跳过了第二个标记,因此最终得到3个结果而不是4个结果,并忽略它,就好像它不存在一样。 Does anybody know why this would be??
有人知道为什么会这样吗?
I apologize if my description is terrible! 如果我的描述不好,我深表歉意!
I can tell you for sure the the index of child nodes - what you're indexing with [loc] - is zero-based. 我可以肯定地告诉您,子节点的索引-您正在使用[loc]进行索引的索引-从零开始。 I'm not sure why a consistently second node would be skipped without more info.
我不确定为什么在没有更多信息的情况下会跳过一致的第二个节点。
But have you tried starting with loc=0 ? 但是您是否尝试从loc = 0开始?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.