簡體   English   中英

從外部網頁(php或java)獲取價值

[英]get value from external webpage (php or java)

我需要從外部網頁獲取電話號碼

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

然后顯示數字

在Java中,您可以使用HTMLUnit庫。 擅長HTML提取。 例如類似於以下內容:

webClient=new WebClient();
HtmlPage page=webClient.getPage(url);
for(HtmlElement elem:page.getElementsByTagName("span")) {
   //And then getChildren(), getText ...
}

以下代碼有效。 我已將此線程用作源頁面。

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

如果您知道頁面的地址,並且確定其內容在此期間不會更改,則可以通過DOM查找編號 但我需要有關您的問題的更多詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM