doudeng9425 2017-01-19 12:36
浏览 34

PHP - 显示外部网站的表格

I need to display a table from an external website on my own website. The reason is that the content of this table changes daily and I don't want to change it manually on my website.

This is my approach so far:

<!-- This is the exemplary HTML code of the external website -->
<html>
  <head>...</head>
  <body>
    <!-- some content -->
    <div id="table-id">
      <table>
        <!-- table content -->
      </table>
    </div>
    <!-- some other content -->
  </body>
</html>


<?php
$homepage = file_get_contents('http://www.my-source-website.com');
$homepage = htmlentities($homepage);

libxml_use_internal_errors(true);

$doc = new DOMDocument("1.0", "utf-8");
$doc->validateOnParse = true;
$doc->loadHTML($homepage);

$selector = new DOMXPath($doc);

$result = $selector->query('//div[@id="table-id"]');

foreach($result as $node) {
  echo $node->textContent;
}
?>

This code seems to be not correct. I'm getting a kind of empty result. Am I on the right way to solve my issue?

I know I could solved this issue with an regular expression, but I've read that this wouldn't be a flexible good solution.

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?