【发布时间】:2011-06-02 16:29:13
【问题描述】:
我要解析google和其他搜索系统的搜索结果,我想拿一些带有标签的东西,例如我有:
<span class="tl">
<h3 class="r">
<a class="l noline" onmousedown="return rwt(this,'','','','1','AFQjCNE3QDnLsIkujVElxf1vT7LocQ-YYw','','0CCQQFjAA')" target="_blank" href="http://l2.ru/">
<em>Lineage</em>
2. Oficial servers l2, la2,
<em>lineage</em>
2.
</a>
</h3>
<button class="vspib"></button>
</span>
我想获取标签的所有内部内容,包括,喜欢
<a class="l noline" onmousedown="return rwt(this,'','','','1','AFQjCNE3QDnLsIkujVElxf1vT7LocQ-YYw','','0CCQQFjAA')" target="_blank" href="http://l2.ru/">
<em>Lineage</em>
2. Oficial servers l2, la2,
<em>lineage</em>
2.
</a>
类似
TFHpple *googleParser = [[TFHpple alloc] initWithHTMLData:googleData];
NSArray *linksWithItsNames = [googleParser search:@"//span[@class='tl'/h3[@class='r']"];
TFHppleElement *googleLinkWithItsName = [linksWithItsNames objectAtIndex:0];
NSString *googleFirstLink = [googleLinkWithItsName content];
[myWebView loadHTMLString:googleFirstLink baseURL:requestURL];
最后我想在我的 WebView 链接中显示它的名称,其中包含(所以我想忽略里面的所有 b、em、br 等标签),以及它的@href。
我刚刚看到 1 个问题 - Ignoring / skipping known or all subordinated tags with XPath 但不明白我应该如何忽略内部标签以及如何将内部文本及其标签作为字符串。 谢谢
【问题讨论】:
标签: iphone objective-c parsing xpath hpple