获取所有
的内容
内的标签在 iPhone 中使用 html 解析器 Hpple
我想为我的 iPhone 应用程序解析以下 html 代码,
<Html>
<body>
<div class="div_1">
<div class="div_2">some code....</div>
<div class="div_3">
<div class="div_4">
<div class="div_5">
<p>First Paragraph</p>
<p>Second Paragraph</p>
<p>Third Paragraph</p>
<p>Fourth Paragraph</p>
</div>
</div>
</div>
</div>
</body>
</Html>
我正在使用 Hpple 解析器来解析此 html。 我正在使用的 xpath 查询是
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:getHTMLData];
NSArray *elementsToSearch = [xpathParser searchWithXPathQuery:@"//div[@class='div_5']/p"];
TFHppleElement *element = [elementsToSearch objectAtIndex:0];
我想要获取的是 div class="div_5" 内的所有 p 标签内容。 使用上面的 xpath 查询我只获取第一个 p 标签内容,即“第一段”。 我的 xpath 做错了什么吗?
I want to parse the following html code for my iphone application
<Html>
<body>
<div class="div_1">
<div class="div_2">some code....</div>
<div class="div_3">
<div class="div_4">
<div class="div_5">
<p>First Paragraph</p>
<p>Second Paragraph</p>
<p>Third Paragraph</p>
<p>Fourth Paragraph</p>
</div>
</div>
</div>
</div>
</body>
</Html>
I am using Hpple parser for parsing this html.
The xpath query that I am using is
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:getHTMLData];
NSArray *elementsToSearch = [xpathParser searchWithXPathQuery:@"//div[@class='div_5']/p"];
TFHppleElement *element = [elementsToSearch objectAtIndex:0];
What I intent to get is all the p tag contents inside of div class="div_5".
Using the above xpath query i am only getting the first p tag contents i.e "First Paragraph".
Am i doing anything wrong in my xpath?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不会。结果全部位于
-searchWithXPathQuery
返回的elementsToSearch
中。尝试检查一下:
No. The results are all in
elementsToSearch
returned by-searchWithXPathQuery
.Try to check out: