【发布时间】:2014-08-20 11:02:53
【问题描述】:
我正在尝试使用 Xpath 查询字符串(在 iOS 的 Objective-C 中)解析 HTML。我正在抓取我想要的元素,但是 除了 的所有内容。
示例 html:
<textarea type="text" name="name" style="width: 100px; height:100px;"/>Contents</textarea>
我尝试抓取元素:
TFHpple *parser = [TFHpple hppleWithHTMLData:response];
NSString *XpathQueryString = @"//textarea[@name='name']";
NSArray *nodes = [parser searchWithXPathQuery:XpathQueryString];
nodes数组中元素的NSLog:
nodeAttributeArray = (
{
attributeName = type;
nodeContent = text;
},
{
attributeName = name;
nodeContent = name;
},
{
attributeName = style;
nodeContent = "width: 100px; height:100px;";
}
);
nodeName = textarea;
raw = "<textarea type=\"text\" name=\"name\" style=\"width: 100px; height:100px;\"></textarea>";
}
没有内容。关于出了什么问题的任何想法?
提前致谢!
【问题讨论】:
-
好吧,
<textarea type="text" name="name" style="width: 100px; height:100px;"/>是一个空元素,因为尾随/>关闭了标签,至少在 X(HT)ML 语法中是这样。另一方面,纯 XML 解析会在随后的</textarea>上给出错误。 -
好的,我现在看到了。那么这是我试图解析的问题还是我试图解析它的问题?
标签: html ios iphone xpath hpple