Web サイトからページ ソースを取得し、コードのスニペットのみを保存するプログラムを構築しようとしています。
package Program;
import java.net.*;
import java.util.*;
public class Program {
public static void main(String[] args) {
String site = "http://www.amazon.co.uk/gp/product/B00BE4OUBG/ref=s9_ri_gw_g63_ir01?pf_rd_m=A3P5ROKL5A1OLE&pf_rd_s=center-5&pf_rd_r=0GJRXWMKNC5559M5W2GB&pf_rd_t=101&pf_rd_p=394918607&pf_rd_i=468294";
try {
URL url = new URL(site);
URLConnection connection = url.openConnection();
connection.connect();
Scanner in = new Scanner(connection.getInputStream());
while (in.hasNextLine()) {
System.out.println(in.nextLine());
}
} catch (Exception e) {
System.out.println(e);
}
}
}
これまでのところ、これは出力にコードを表示するだけです。プログラムで特定の文字列を検索し、価格のみを表示するようにしたいと考えています。例えば
<tr id="actualPriceRow">
<td id="actualPriceLabel" class="priceBlockLabelPrice">Price:</td>
<td id="actualPriceContent"><span id="actualPriceValue"><b class="priceLarge">£599.99</b></span>
<span id="actualPriceExtraMessaging">
class="priceLarge">
599.99 を検索して表示/保存する
Web サイトに同様の質問があることは知っていますが、PHP をよく理解していないため、Java ソリューションが必要ですが、どのようなソリューションも歓迎します :)