duanla3319 2013-04-02 03:57
浏览 23
已采纳

从外部页面获取值?

this code is in an external url: www.example.com.

</head><body><div id="cotizaciones"><h1>Cotizaciones</h1><table cellpadding="3" cellspacing="0" class="tablamonedas">
  <tr style="height:19px"><td class="1"><img src="../mvd/usa.png" width="24" height="24" /></td>
  <td class="2">19.50</td>
  <td class="3">20.20</td>
  <td class="4"><img src="../mvd/Bra.png" width="24" height="24" /></td>
<td class="5">9.00</td>
<td class="6">10.50</td>
  </tr><tr style="height:16px" valign="bottom"><td class="15"><img src="../mvd/Arg.png" width="24" height="24" /></td>
<td class="2">2.70</td>
<td class="3">3.70</td>
<td class="4"><img src="../mvd/Eur.png" width="24" height="24" /></td>
<td class="5">24.40</td>
<td class="6">26.10</td>
</tr></table>

i want to get the values of the td, any suggestions? php,jquery etc.

  • 写回答

2条回答 默认 最新

  • dou7466 2013-04-02 04:06
    关注

    You won't be able to do this with javascript, due to security restrictions that only allow you to load data from your own site.

    You will have to pull the content with php (using something as simple as file_get_contents) and then parse it.

    For the parsing, take a read through this comprehensive post:

    How do you parse and process HTML/XML in PHP?

    DOM is likely going to be your best bet.

    Try playing around with this:

    $html = file_get_contents('/path/to/remote/page/');
    $dom = new DOMDocument;
    $dom->loadHTML($html);
    foreach ($dom->getElementsByTagName('td') as $node) {
        echo "Full TD html: " . $dom->saveHtml($node) . "
    ";
        echo "TD contents: " . $node->nodeValue . "
    
    ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab