0

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.

İsmet Alkan
  • 5,361
  • 3
  • 41
  • 64
jandresrodriguez
  • 794
  • 7
  • 18

2 Answers2

4

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) . "\n";
    echo "TD contents: " . $node->nodeValue . "\n\n";
}
Community
  • 1
  • 1
jszobody
  • 28,495
  • 6
  • 61
  • 72
0

Its not possible to do with jquery, however you can easily do it with PHP.

Use file_get_contents to read entire source code of the page into a string.

Parse, tokenise the string that contains the entire page source in order to grab all the td value.

<?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;

?>

You have to be very careful while parsing the string to get desired output.For parsing you can either use regular expression or create your own look up table.You can use a HTML DOM parser written in PHP5 that let you manipulate HTML in a very easy way.A lot of such free parsers are available.

Ritesh Kumar Gupta
  • 5,055
  • 7
  • 45
  • 71