Java Code Examples for org.jsoup.nodes.Element#getElementsByAttribute()
The following examples show how to use
org.jsoup.nodes.Element#getElementsByAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CityStats.java From zuihou-admin-boot with Apache License 2.0 | 5 votes |
public static void parseProvince(String url) { String htmlStr = HttpUtil.get(url, CHARSET); Document document = Jsoup.parse(htmlStr); // 获取 class='provincetr' 的元素 Elements elements = document.getElementsByClass("provincetr"); List<Area> provinces = new LinkedList<Area>(); int sort = 1; for (Element element : elements) { // 获取 elements 下属性是 href 的元素 Elements links = element.getElementsByAttribute("href"); for (Element link : links) { String provinceName = link.text(); String href = link.attr("href"); String provinceCode = href.substring(0, 2); StaticLog.info("provinceName: {} , provinceCode: {} .", provinceName, provinceCode); Area provinceArea = Area.builder().code(provinceCode).label(provinceName).source(url) .sortValue(sort++).fullName(provinceName).level(new RemoteData<>("PROVINCE")) .build(); StaticLog.info("省级数据: {} ", provinceArea); parseCity(COMMON_URL + href, provinceArea); provinces.add(provinceArea); } } StaticLog.info(JSONUtil.toJsonPrettyStr(provinces)); }
Example 2
Source File: CityParser.java From zuihou-admin-boot with Apache License 2.0 | 5 votes |
private List<Area> parseProvince(String url) { String htmlStr = HttpUtil.get(url, CHARSET); Document document = Jsoup.parse(htmlStr); // 获取 class='provincetr' 的元素 Elements elements = document.getElementsByClass("provincetr"); List<Area> provinces = new LinkedList<Area>(); int sort = 1; for (Element element : elements) { // 获取 elements 下属性是 href 的元素 Elements links = element.getElementsByAttribute("href"); for (Element link : links) { String provinceName = link.text(); String href = link.attr("href"); String provinceCode = href.substring(0, 2); Area provinceArea = Area.builder().code(provinceCode + "0000") .label(provinceName).source(url) .sortValue(sort++) .level(new RemoteData<>("PROVINCE")) .fullName(provinceName) .build(); provinceArea.setChildren(parseCity(provinceName, COMMON_URL + href)); StaticLog.info("省级数据: {} ", provinceArea); provinces.add(provinceArea); } } return provinces; }
Example 3
Source File: CityStats.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
public static void parseProvince(String url) { String htmlStr = HttpUtil.get(url, CHARSET); Document document = Jsoup.parse(htmlStr); // 获取 class='provincetr' 的元素 Elements elements = document.getElementsByClass("provincetr"); List<Area> provinces = new LinkedList<Area>(); int sort = 1; for (Element element : elements) { // 获取 elements 下属性是 href 的元素 Elements links = element.getElementsByAttribute("href"); for (Element link : links) { String provinceName = link.text(); String href = link.attr("href"); String provinceCode = href.substring(0, 2); StaticLog.info("provinceName: {} , provinceCode: {} .", provinceName, provinceCode); Area provinceArea = Area.builder().code(provinceCode).label(provinceName).source(url) .sortValue(sort++).fullName(provinceName).level(new RemoteData<>("PROVINCE")) .build(); StaticLog.info("省级数据: {} ", provinceArea); parseCity(COMMON_URL + href, provinceArea); provinces.add(provinceArea); } } StaticLog.info(JSONUtil.toJsonPrettyStr(provinces)); }
Example 4
Source File: CityParser.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
private List<Area> parseProvince(String url) { String htmlStr = HttpUtil.get(url, CHARSET); Document document = Jsoup.parse(htmlStr); // 获取 class='provincetr' 的元素 Elements elements = document.getElementsByClass("provincetr"); List<Area> provinces = new LinkedList<Area>(); int sort = 1; for (Element element : elements) { // 获取 elements 下属性是 href 的元素 Elements links = element.getElementsByAttribute("href"); for (Element link : links) { String provinceName = link.text(); String href = link.attr("href"); String provinceCode = href.substring(0, 2); Area provinceArea = Area.builder().code(provinceCode + "0000") .label(provinceName).source(url) .sortValue(sort++) .level(new RemoteData<>("PROVINCE")) .fullName(provinceName) .build(); provinceArea.setChildren(parseCity(provinceName, COMMON_URL + href)); StaticLog.info("省级数据: {} ", provinceArea); provinces.add(provinceArea); } } return provinces; }
Example 5
Source File: JSInterface.java From NoVIP with Apache License 2.0 | 5 votes |
@JavascriptInterface public void showSource(String html) { Log.d("HTML", html); Element body = Jsoup.parse(html).body(); Elements elements = body.getElementsByAttribute("src"); for(Element e: elements){ if(e.tagName().equals("video")){ for(DataNode node : e.dataNodes()){ if(node.nodeName().equals("src")){ Log.d("JSInterface",node.getWholeData()); } } } Log.d("JSInterface",e.toString()); } /*Elements elements = body.getElementsByTag("body"); if(elements != null && !elements.isEmpty()){ elements = elements.get(0).getElementsByTag("video"); if(elements != null && !elements.isEmpty()){ Log.d("JSInterface",elements.get(0).toString()); elements = elements.get(0).getElementsByAttribute("src"); if(elements != null && !elements.isEmpty()){ Log.d("JSInterface",elements.get(0).toString()); } } }else { Log.d("JSInterface","没有Video"); }*/ FileUtils.saveFile("video.html",html); }