I need to get a number from a external webpage
<span>
<b>Maximum price:</b>
7 //value i need
</span>
Then display said number
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 ...
}
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];
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.