douyan8961 2016-08-05 07:58
浏览 78

如何通过PHP或JavaScript读取外部iframe

I want to track my package sent via the local post service: http://tandt.posta.sk/en.

With the tracking information, for example, RF166699170SK, I can locate the package.

but when I want to read it via PHP for example curl_setopt, via file_get_contents, or another method, I read only HTML code but in output missing text for example "Item posted at post office Dlhé Pole" which I can see on page.

because this page use iframe with some private method http://www.posta.sk/en/sps-embed#tnt?q=RF166699170SK

but when I try to read this page (iframe), output missing information about package for example "Item posted at post office Dlhé Pole".

Output:

<!DOCTYPE html>
<html class="embed">
  <head>
    <link href="/sps/style.css?1450227250" media="screen,print" rel="stylesheet" type="text/css" />
    <link href="/sps/print.css?1445466449" media="print" rel="stylesheet" type="text/css" />
    <title>Slovenská pošta</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="google" value="notranslate">
    <script type="text/javascript">CONFIG={"api":"http://api.posta.sk/private","tntShare":{"en":"http://tandt.posta.sk/en/items/{number}","sk":"http://tandt.posta.sk/zasielky/{number}"},"lang":"sk","home":"http://www.posta.sk","embed":true}</script>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
    <script src="/sps/script.js?1457665771" type="text/javascript"></script>
      </head>
  <body>
    <script type="text/javascript">
//<![CDATA[
      var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
      document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
//]]>
</script><script type="text/javascript">
//<![CDATA[
      try {
        var pageTracker = _gat._getTracker("UA-9600731-1");
        pageTracker._setDomainName("posta.sk");
        pageTracker._initData();
        pageTracker._trackPageview();
      } catch(err) {}
//]]>
</script>
  </body>
</html>

Is it possible to read about this parcel via PHP or JavaScript?

  • 写回答

2条回答 默认 最新

  • dpb42021 2016-08-05 08:11
    关注

    If you inspect network connection of the page you linked you can see that there some data is loaded via JSON request. In your example data is requested from http://api.posta.sk/private/search?q=RF166699170SK&m=tnt

    Maybe it would be the easiest way to get data direct from this API instead of trying to parse the result. The key is the same. You can convert the response in php like this:

    <?php
        $packageKey = 'RF166699170SK';
        $data = json_decode('http://api.posta.sk/private/search?q='.$packageKey.'&m=tnt', TRUE);
    ?>
    

    But I don't know if it's allowed by your postal service. You should ask if it's prohibited to do that.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line