【问题标题】:php extract only selected rows from external tablephp只从外部表中提取选定的行
【发布时间】:2014-04-29 10:10:12
【问题描述】:

我只想从外部站点上存在的表中提取选定数量的行。我使用以下帖子中的响应作为提取整个表格的开始:

PHP Data Extraction From External Website, Then Write to Database

它非常适合获取整个表,但我想要完成的内容如下。

1) 排除第一行

2) 包括接下来的 7 行

3) 排除表格的其余部分

这个可以吗?

【问题讨论】:

  • 是的,这可以做到。你在研究手头的问题时想到了什么?为什么它对你不起作用?你被困在哪里了?
  • 我开始发现处理的是正则表达式,这超出了我的经验范围。
  • 我可以获取整个表,但要操作检索到的数据以仅获取我想要的行是我卡住的地方。
  • 查看链接的问题。我的偏好是nl3.php.net/manual/en/class.domdocument.php

标签: php regex dom curl scrape


【解决方案1】:

出于我的特定目的,我使用了以下课程 http://sourceforge.net/projects/simplehtmldom/

下面的 php 代码可以从我正在抓取的 html 表中得到我想要的。

    <?php 

    include('../includes/simple_html_dom.php');

    $html = file_get_html('http://listhoopla.com/r.cgi/276');

    $ret = $html->find('tr');

    ?><table><?
    $x=1;
    while($x<8){
    echo $ret[$x];
    $x++;
    }
    ?>
    </table>

【讨论】:

    猜你喜欢
    • 2018-10-06
    • 1970-01-01
    • 2015-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2022-01-09
    相关资源
    最近更新 更多