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条)

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改