嘿,我很难尝试从使用XPath的网站获取股票价格。如何使用XPath从html中检索特定数据?
的HTML是这样的:
<span class=" price">
<meta content="14.400" itemprop="price">
14.400
<span itemprop="priceCurrency"> BRL</span>
</span>
我用来检索14.400值(所有的人都让我空)的路径,分别为:
@"//span[@class=' price']";
@"/span[@class=' price']";
@"span[@class=' price']";
@"//meta[@itemprop='price'"];
@"/html/body/div[2]/div/div/div/div[2]/span/meta";
@"//html/body/div[2]/div/div/div/div[2]/span/meta";
尝试了很多最接近后我能得到我所需要的就是用这个XPATH:
@"//span[@class=' price']/meta";
得到这个日志:
2014-02-07 13:50:39.616 manejoderisco[2838:60b] {
nodeAttributeArray = (
{
attributeName = itemprop;
nodeContent = price;
},
{
attributeName = content;
nodeContent = "14.280";
}
);
nodeName = meta;
}
不过还是我返回空值...
你的HTML结构不好......(不会关闭'meta'标签)。这是你真正处理的代码吗?这可能没有帮助。 – Robin
是的,我知道没有关闭元标记,但原始代码就是这样,没有关闭标记。 –