@Test public void parseJD() { boolean java = searchJDService.parseJD("docker"); System.out.println(java); }
public static List<SearchJDResultDTO> parseJd(String keyword) { try { String url = "https: Document document = Jsoup.connect(url).timeout(5 * 1000).get(); Element elementById = document.getElementById("J_goodsList"); Elements elements = elementById.getElementsByTag("li"); ArrayList<SearchJDResultDTO> list = Lists.newArrayList(); for (Element element : elements) { String img = element.getElementsByTag("img").eq(0).attr("src"); if (img == null) { img = element.getElementsByTag("img").eq(0).attr("source-data-lazy-img"); } String price = element.getElementsByClass("p-price").eq(0).text(); String title = element.getElementsByClass("p-name").eq(0).text(); SearchJDResultDTO searchJDResultDTO = new SearchJDResultDTO(img, price, title); list.add(searchJDResultDTO); } return list; } catch (IOException e) { e.printStackTrace(); throw new BaseException(ResultCode.PARAMETER_INVALID, ResultCode.MSG_PARAMETER_INVALID); } }
JsoupJDUtil { public static List<SearchJDResultDTO> parseJd(String keyword) { try { String url = "https: Document document = Jsoup.connect(url).timeout(5 * 1000).get(); Element elementById = document.getElementById("J_goodsList"); Elements elements = elementById.getElementsByTag("li"); ArrayList<SearchJDResultDTO> list = Lists.newArrayList(); for (Element element : elements) { String img = element.getElementsByTag("img").eq(0).attr("src"); if (img == null) { img = element.getElementsByTag("img").eq(0).attr("source-data-lazy-img"); } String price = element.getElementsByClass("p-price").eq(0).text(); String title = element.getElementsByClass("p-name").eq(0).text(); SearchJDResultDTO searchJDResultDTO = new SearchJDResultDTO(img, price, title); list.add(searchJDResultDTO); } return list; } catch (IOException e) { e.printStackTrace(); throw new BaseException(ResultCode.PARAMETER_INVALID, ResultCode.MSG_PARAMETER_INVALID); } } }
JsoupJDUtil { public static List<SearchJDResultDTO> parseJd(String keyword) { try { String url = "https: Document document = Jsoup.connect(url).timeout(5 * 1000).get(); Element elementById = document.getElementById("J_goodsList"); Elements elements = elementById.getElementsByTag("li"); ArrayList<SearchJDResultDTO> list = Lists.newArrayList(); for (Element element : elements) { String img = element.getElementsByTag("img").eq(0).attr("src"); if (img == null) { img = element.getElementsByTag("img").eq(0).attr("source-data-lazy-img"); } String price = element.getElementsByClass("p-price").eq(0).text(); String title = element.getElementsByClass("p-name").eq(0).text(); SearchJDResultDTO searchJDResultDTO = new SearchJDResultDTO(img, price, title); list.add(searchJDResultDTO); } return list; } catch (IOException e) { e.printStackTrace(); throw new BaseException(ResultCode.PARAMETER_INVALID, ResultCode.MSG_PARAMETER_INVALID); } }  }
JsoupJDUtil { public static List<SearchJDResultDTO> parseJd(String keyword) { try { String url = "https: Document document = Jsoup.connect(url).timeout(5 * 1000).get(); Element elementById = document.getElementById("J_goodsList"); Elements elements = elementById.getElementsByTag("li"); ArrayList<SearchJDResultDTO> list = Lists.newArrayList(); for (Element element : elements) { String img = element.getElementsByTag("img").eq(0).attr("src"); if (img == null) { img = element.getElementsByTag("img").eq(0).attr("source-data-lazy-img"); } String price = element.getElementsByClass("p-price").eq(0).text(); String title = element.getElementsByClass("p-name").eq(0).text(); SearchJDResultDTO searchJDResultDTO = new SearchJDResultDTO(img, price, title); list.add(searchJDResultDTO); } return list; } catch (IOException e) { e.printStackTrace(); throw new BaseException(ResultCode.PARAMETER_INVALID, ResultCode.MSG_PARAMETER_INVALID); } }  static List<SearchJDResultDTO> parseJd(String keyword); static void main(String[] args); }
JsoupJDUtil { public static List<SearchJDResultDTO> parseJd(String keyword) { try { String url = "https: Document document = Jsoup.connect(url).timeout(5 * 1000).get(); Element elementById = document.getElementById("J_goodsList"); Elements elements = elementById.getElementsByTag("li"); ArrayList<SearchJDResultDTO> list = Lists.newArrayList(); for (Element element : elements) { String img = element.getElementsByTag("img").eq(0).attr("src"); if (img == null) { img = element.getElementsByTag("img").eq(0).attr("source-data-lazy-img"); } String price = element.getElementsByClass("p-price").eq(0).text(); String title = element.getElementsByClass("p-name").eq(0).text(); SearchJDResultDTO searchJDResultDTO = new SearchJDResultDTO(img, price, title); list.add(searchJDResultDTO); } return list; } catch (IOException e) { e.printStackTrace(); throw new BaseException(ResultCode.PARAMETER_INVALID, ResultCode.MSG_PARAMETER_INVALID); } }  static List<SearchJDResultDTO> parseJd(String keyword); static void main(String[] args);  }