使用 Php 从特定 HTML 表格单元格获取数据

发布于 2024-09-29 09:30:03 字数 145 浏览 0 评论 0原文

我需要从 HTML 页面上第 4 个表的第 4 行的所有表格单元格中获取数据。经过一段时间的研究,似乎使用 DOMXPath 是解析​​ HTML 文件的最佳方法。但是,文件中的任何位置均未使用 ID 或类。从这些单元格中获取数据的最佳方法是什么?

提前致谢。

I need to get the data out of all of the table cells in the 4th row of the 4th table on an HTML page. After researching for a while, it seems that using DOMXPath is the best way to parse the HTML file. However, no IDs or classes are used anywhere in the file. What would be the best way to get the data out of these cells?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

温柔戏命师 2024-10-06 09:30:03

使用 XPath 获取时可以指定索引。在您的情况下

/html/body/table[4]/tbody/tr[4]/td

请注意, XPath 索引不是从零开始,但从一开始

You can specify an index when fetching with XPath. In your case

/html/body/table[4]/tbody/tr[4]/td

Note that an XPath index is not zero-based, but one-based.

猥︴琐丶欲为 2024-10-06 09:30:03

如果您熟悉 jQuery 语法,您是否研究过 phpQuery

If you are familiar with jQuery syntax, have you looked into phpQuery?

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