由於「金額」類用於「我們也推薦」部分中的物品價格,因此它是所有價格而不是主要物品價格。如何讓它在第一個價格之後停止尋找更多價格?這裏是我的代碼:我正嘗試從Best Buy中檢索產品名稱和價格,如何在第一個價格後停止產品名稱和價格?
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class BestBuy {
//retrieves item name and price from Best Buy
public static void main(String[] args) throws Exception {
String url = "http://www.bestbuy.ca/en-CA/product/samsung-samsung-galaxy-tab-3- 8-0-16gb-android-4-2-tablet-with-exynos-4212-processor-white-sm-t310/10254746.aspx?path=8654a6d491c7d5a9465456671fa126e4en02";
Document document = Jsoup.connect(url).get();
String amount = document.select(".amount").text();
System.out.println("Price: " + amount);
String name = document.select(".product-title").text();
System.out.println("Item Name: " + name);
}
}
謝謝。