获取所有

的内容

内的标签在 iPhone 中使用 html 解析器 Hpple

发布于 2025-01-04 09:36:49 字数 987 浏览 3 评论 0原文

我想为我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┾廆蒐ゝ 2025-01-11 09:36:49

不会。结果全部位于 -searchWithXPathQuery 返回的 elementsToSearch 中。

尝试检查一下:

NSLog(@"%@",[elementsToSearch description]);

No. The results are all in elementsToSearch returned by -searchWithXPathQuery.

Try to check out:

NSLog(@"%@",[elementsToSearch description]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文