0

I need to get a number from a external webpage

<span>
<b>Maximum price:</b>
7 //value i need
</span>

Then display said number

Anthony
  • 1
  • 1
  • 1

3 Answers3

2

In Java you can use HTMLUnit library. It's good at HTML extraction. For example something similar to:

webClient=new WebClient();
HtmlPage page=webClient.getPage(url);
for(HtmlElement elem:page.getElementsByTagName("span")) {
   //And then getChildren(), getText ...
}
lujop
  • 13,504
  • 9
  • 62
  • 95
1

The following code works. I've used this thread as the source page.

<?php

// Read the whole file.
$lines = file('http://stackoverflow.com/questions/4573498/get-value-from-external-webpage-php-or-java');

// Go through every line ..
while ($line = array_shift($lines)) {

        // Stop when you find the label we're looking for.
        if (strpos($line, 'Maximum price') !== false) break;

}

// The next line has your value on it.
$line = array_shift($lines);

// Print the first word on the line.
$values = explode(' ', $line);
echo $values[0];
Andrew Culver
  • 1,967
  • 2
  • 13
  • 7
0

If you know the address of the page and you are sure that their content will not change during the time, you can find the number by means of DOM. But I need more detail about your problem.

ehsun7b
  • 4,796
  • 14
  • 59
  • 98
  • http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=1040 Im trying to get the min man and market price values. – Anthony Jan 01 '11 at 21:55
  • At first download the PHP Simple HTML DOM Parser here: http://sourceforge.net/projects/simplehtmldom/files/ then you can use its examples here: http://simplehtmldom.sourceforge.net/ If you need more help please let me know. – ehsun7b Jan 02 '11 at 08:04
  • // Create DOM from URL or file $html = file_get_html('http://www.google.com/'); // Find all images foreach($html->find('img') as $element) echo $element->src . '
    '; // Find all links foreach($html->find('a') as $element) echo $element->href . '
    ';
    – ehsun7b Jan 02 '11 at 08:07