Php 从外部页面获取值?

Php 从外部页面获取值?,php,javascript,jquery,Php,Javascript,Jquery,此代码位于外部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="../

此代码位于外部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>
cotizaiones
19.50
20.20
9
10.50
2.70
3.70
24.40
26.10

我想知道td的值,有什么建议吗?php、jquery等。

由于只允许您从自己的站点加载数据的安全限制,您将无法使用javascript执行此操作

您必须使用php(使用像这样简单的东西)提取内容,然后解析它

对于解析,请通读这篇综合文章:

很可能是你最好的选择

试着玩一下这个:

$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) . "\n";
    echo "TD contents: " . $node->nodeValue . "\n\n";
}

由于只允许您从自己的站点加载数据的安全限制,您将无法使用javascript执行此操作

您必须使用php(使用像这样简单的东西)提取内容,然后解析它

对于解析,请通读这篇综合文章:

很可能是你最好的选择

试着玩一下这个:

$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) . "\n";
    echo "TD contents: " . $node->nodeValue . "\n\n";
}

使用jquery是不可能的,但是使用PHP可以很容易地做到

用于将页面的整个源代码读入字符串

解析、标记包含整个页面源的字符串,以便获取所有td值

<?php
$srccode = file_get_contents('http://www.example.com/');
/*$src is a string that contains source code of web-page http://www.example.com/

/*Now only thing you have to do is write a function say "parser" that tokenise or parse the string in order to grab all the td value*/

$output=parser($srccode);
echo $output;

?>


在解析字符串以获得所需输出时,您必须非常小心。对于解析,您可以使用正则表达式或创建自己的查找表。您可以使用用PHP5编写的HTML DOM解析器,它可以让您以非常简单的方式操作HTML。有很多这样的免费解析器可用。

使用jquery是不可能的,但是,您可以使用PHP轻松地完成它

用于将页面的整个源代码读入字符串

解析、标记包含整个页面源的字符串,以便获取所有td值

<?php
$srccode = file_get_contents('http://www.example.com/');
/*$src is a string that contains source code of web-page http://www.example.com/

/*Now only thing you have to do is write a function say "parser" that tokenise or parse the string in order to grab all the td value*/

$output=parser($srccode);
echo $output;

?>


在解析字符串以获得所需输出时,您必须非常小心。对于解析,您可以使用正则表达式或创建自己的查找表。您可以使用用PHP5编写的HTML DOM解析器,它可以让您以非常简单的方式操作HTML。有很多这样的免费解析器可用。

您是如何获得这些数据的?使用PHP,还是使用JavaScript?浏览器不允许在JavaScript中使用此功能,因为存在错误。我不介意它是PHP还是JavaScript,我想获取该值显示您是否获取该数据?使用PHP,还是使用JavaScript?浏览器不允许在JavaScript中使用此选项,因为存在错误。我不介意它是PHP还是JavaScript,我想获取该值