使用jsoup搜索查询

时间:2015-11-09 01:21:31

标签: java jquery jsoup

我想使用此链接使用jsoup搜索项目,例如我想找到powerbank

http://www.mudah.my/li?frmsrch=1&fs=1&ca=9_s&cg=0&w=3&so=1&st=s&q=powerbank

我希望jsoup提取并提供输出下面可用的powerbank enter image description here

  String SEARCH_STRING = "powerbank";
    String URL = "http://www.lazada.com.my/catalog/?q=";


    Document doc = Jsoup.connect(URL + SEARCH_STRING)
            .referrer(URL + SEARCH_STRING).get();
谁能帮助我吗?非常感谢你

1 个答案:

答案 0 :(得分:0)

请检查。

Elements elements = doc.select("li div.product-description");

for (Element element : elements) {

    String title = element.select("a.product-name").first().attr("title");  
    String img = element.select("img").first().attr("src");
    String href = element.select("a").first().attr("href"); 
    String priceNormal = element.select("span.product-price-normal").first().text();    
    String priceDiscount = element.select("span.product-price-discount").isEmpty() ? "-" : element.select("span.product-price-discount").first().text();    
    String priceDiscountPercent = element.select("div.product-discount").isEmpty() ? "0" : element.select("div.product-discount").first().text();

}