[英]get value from external webpage (php or java)
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. 在Java中,您可以使用HTMLUnit库。 It's good at HTML extraction.
擅长HTML提取。 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. 如果您知道页面的地址,并且确定其内容在此期间不会更改,则可以通过DOM查找编号 。 But I need more detail about your problem.
但我需要有关您的问题的更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.