使用 jsoup 搜索查询
search query using jsoup
我想使用这个 link 使用 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();
谁能帮帮我?非常感谢
请查收。
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();
}
我想使用这个 link 使用 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();
谁能帮帮我?非常感谢
请查收。
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();
}