Jsoup遍历ul li下的链接信息实例

2019独角兽企业重金招聘Python工程师标准>>> hot3.png


		Document doc;
		try {
			String URL = "www.baidu.com";
			doc = Jsoup.connect(URL).get();
			Elements ElementsUl = doc.getElementsByTag("ul");
			for (Element elementLi : ElementsUl) {
				Elements provinceEl = elementLi.getElementsByTag("li");
				for (Element element : provinceEl) {
					String categroyName = element.text();
					Element el = element.select("a").first();
					String url = el != null ? el.attr("href") : "";
					String letter = PinYinUtils.convertUpper(categroyName);
					letter = letter.substring(0, 1);
					categroyName = ReplaceUtils.replaceBrackets(categroyName);
					categroyName = ReplaceUtils.removeDigital(categroyName);
					System.out.println(categroyName);
					System.out.println(url);
					System.out.println(letter);
					insert(letter, categroyName, url);
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	

 

转载于:https://my.oschina.net/ydsakyclguozi/blog/902985

你可能感兴趣的:(Jsoup遍历ul li下的链接信息实例)