List of usage examples for org.jsoup.nodes Element child
public Element child(int index)
From source file:io.github.carlomicieli.footballdb.starter.parsers.PlayerCareerParser.java
private static Map<String, String> extractValues(Element el) { Map<String, String> values = new HashMap<>(); values.put("SeasonStats", el.child(0).text()); values.put("Team", el.child(1).text()); values.put("G", el.child(2).text()); values.put("GS", el.child(3).text()); return Collections.unmodifiableMap(values); }
From source file:org.shareok.data.plosdata.PlosUtil.java
/** * //from w w w . j a v a2s . c o m * @param html : The string of the web page source * @return acknowledge statement */ public static String[] getSubjects(String html) { List<String> subjectsList = new ArrayList<>(); Document doc = Jsoup.parse(html.toString()); Elements subjectListDiv = doc.select("div[class=subject-areas-container]"); if (null != subjectListDiv && !subjectListDiv.isEmpty()) { Element subjectList = subjectListDiv.first().child(1); if (null != subjectList) { Elements lis = subjectList.select("li"); if (null != lis && lis.size() > 0) { for (Element li : lis) { Element link = li.child(0); subjectsList.add(link.text()); } } } } if (subjectsList.size() > 0) { return subjectsList.toArray(new String[subjectsList.size()]); } else { return null; } }
From source file:com.megatome.j2d.support.JavadocSupport.java
private static List<SearchIndexValue> indexFile(File f) throws BuilderException { final List<SearchIndexValue> values = new ArrayList<>(); final Elements elements = loadAndFindLinks(f); for (final Element e : elements) { Element parent = e.parent(); if (!parent.child(0).equals(e)) { continue; }/* w ww . ja v a 2s .c om*/ final String parentTagName = parent.tagName(); if (parentPattern.matcher(parentTagName).matches()) { parent = parent.parent(); if (!parent.child(0).equals(e.parent())) { continue; } } if (!containsIgnoreCase(parentTagName, "dt")) { continue; } final String text = parent.text(); final String name = e.text(); final String className = parent.className(); final MatchType type = getMatchingType(text, className); if (null == type) { System.err.println(String.format( "Unknown type found. Please submit a bug report. (Text: %s, Name: %s, className: %s)", text, name, className)); continue; } try { final String linkPath = URLDecoder.decode(e.attr("href"), "UTF-8"); values.add(new SearchIndexValue(name, type, linkPath)); } catch (UnsupportedEncodingException ex) { throw new BuilderException("Error decoding a link", ex); } } return values; }
From source file:com.megatome.j2d.support.JavadocSupport.java
private static List<SearchIndexValue> indexClassFile(File f) throws BuilderException { final List<SearchIndexValue> values = new ArrayList<>(); final Elements elements = loadAndFindLinks(f); String lastContext = ""; for (final Element e : elements) { Element parent = e.parent(); if (!parent.child(0).equals(e)) { continue; }// w w w .j a v a 2 s . co m if (e.hasAttr("name")) { lastContext = e.attr("name"); } final String parentTagName = parent.tagName(); final String parentClassName = parent.className(); if (parentPattern.matcher(parentTagName).matches()) { parent = parent.parent(); if (!parent.child(0).equals(e.parent())) { continue; } } if (!containsIgnoreCase(parentTagName, "span") || !containsIgnoreCase(parentClassName, "memberNameLink") || equalsIgnoreCase("nested.class.summary", lastContext) || equalsIgnoreCase("enum.constant.summary", lastContext)) { continue; } final String text = parent.text(); final MatchType type = getMatchingType(lastContext, null); if (null == type) { System.err.println( String.format("Unknown type found. Please submit a bug report. (Text: %s, Context: %s)", text, lastContext)); continue; } try { final String linkPath = URLDecoder.decode(e.attr("href"), "UTF-8").replaceAll("\\.\\.\\/", ""); values.add(new SearchIndexValue(text, type, linkPath)); } catch (UnsupportedEncodingException ex) { throw new BuilderException("Error decoding a link", ex); } } return values; }
From source file:eu.riscoss.rdc.RDCFossology.java
/** * Parses a LicensesCfg file//from w w w. ja v a2s. c o m * @param target * @return HashMap: License Types, each with a Collection of Licenses * @throws IOException */ protected static HashMap<String, Collection<String>> parseLicensesFile(String target) throws IOException { HashMap<String, Collection<String>> result = new HashMap<String, Collection<String>>(); Document document; if (target.startsWith("http")) { document = Jsoup.connect(target).get(); } else { if (target.startsWith("file:")) target = target.substring(5); //File file = new File(target); InputStream in = RDCFossology.class.getResourceAsStream("res/" + target); //System.out.println("Fossology config file used: "+file.getPath()); //System.out.println("Fossology IS file used: "+in.toString()); document = Jsoup.parse(in, "UTF-8", "http://localhost"); } Elements licensesLinks = document.getElementsByAttribute("id"); for (Element element : licensesLinks) { String licenseName = element.child(0).text(); if (element.children().size() > 1) { String s = element.child(1).text(); Collection<String> licensesList = Arrays.asList(s.split("\\s*\\|\\s*")); result.put(licenseName, licensesList); } } return result; }
From source file:eu.riscoss.dataproviders.providers.FossologyDataProvider.java
/** * Parses a LicensesCfg file/*w w w . ja v a 2 s . co m*/ * @param target * @return HashMap: License Types, each with a Collection of Licenses * @throws IOException */ protected static HashMap<String, Collection<String>> parseLicensesFile(String target) throws IOException { HashMap<String, Collection<String>> result = new HashMap<String, Collection<String>>(); Document document; if (target.startsWith("http")) { document = Jsoup.connect(target).get(); } else { File file = new File(target); System.out.println("Fossology config file used: " + file.getCanonicalPath()); document = Jsoup.parse(file, "UTF-8", "http://localhost"); } // System.out.println(document.outerHtml()); Elements licensesLinks = document.getElementsByAttribute("id"); for (Element element : licensesLinks) { String licenseName = element.child(0).text(); if (element.children().size() > 1) { String s = element.child(1).text(); Collection<String> licensesList = Arrays.asList(s.split("\\s*\\|\\s*")); //("\\s*\\|\\s*")); //xDebug System.out.println("Analysed license type: "+licenseName+": "+licensesList); result.put(licenseName, licensesList); } } return result; }
From source file:io.github.carlomicieli.footballdb.starter.parsers.SeasonGamesParser.java
private Game mapToGame(String year, Element e) { String at = e.child(5).text(); Supplier<TeamScore> fst = () -> Game.newTeam(e.child(4).text(), e.child(7).text()); Supplier<TeamScore> snd = () -> Game.newTeam(e.child(6).text(), e.child(8).text()); return Game.builder().type(e.child(0).text()).date(year + " " + e.child(2).text()) .home(select(at, fst, snd)).away(select(at, snd, fst)).build(); }
From source file:de.geeksfactory.opacclient.apis.IOpac.java
static void parseResList(List<ReservedItem> media, Document doc, JSONObject data) { if (doc.select("a[name=RES]").size() == 0) return;// ww w .j a v a 2 s . com Elements copytrs = doc.select("a[name=RES] ~ table:contains(Titel)").first().select("tr"); doc.setBaseUri(data.optString("baseurl")); DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN); int trs = copytrs.size(); if (trs < 2) { return; } assert (trs > 0); for (int i = 1; i < trs; i++) { Element tr = copytrs.get(i); ReservedItem item = new ReservedItem(); item.setTitle(tr.child(0).text().trim().replace("\u00a0", "")); item.setAuthor(tr.child(1).text().trim().replace("\u00a0", "")); try { item.setReadyDate(fmt.parseLocalDate(tr.child(4).text().trim().replace("\u00a0", ""))); } catch (IllegalArgumentException e) { item.setStatus(tr.child(4).text().trim().replace("\u00a0", "")); } if (tr.select("a").size() > 0) { item.setCancelData(tr.select("a").last().attr("href")); } media.add(item); } assert (media.size() == trs - 1); }
From source file:com.liato.bankdroid.banking.banks.Hors.java
private Transaction asTransaction(Element element) { return new Transaction(element.child(0).text().trim(), element.child(1).text().trim(), Helpers.parseBalance(element.child(2).text())); }
From source file:com.mycompany.parcinghtml.ParsingClassPlayers.java
public void downloadSource() throws SQLException { //ds = prepareDataSource(); String sql = "INSERT INTO PLAYERS(NAME,AGE,HEIGHT,WEIGHT,PLAYERNUM,POSITION,PLAYERID) VALUES(?,?,?,?,?,?,?)"; ArrayList<String> duplicity = new ArrayList<>(); int playerID = 1; for (int i = 2015; i > 2004; i--) { Document doc = null;/*from w w w .j a v a 2s .c o m*/ try { doc = Jsoup.connect("http://www.hcsparta.cz/soupiska.asp?sezona=" + Integer.toString(i)).get(); } catch (IOException e) { System.out.println(e.getMessage()); } if (doc == null) { System.out.println("doc is null"); return; } Elements posNum; Elements elList; posNum = doc.getElementsByAttributeValueContaining("class", "soupiska"); //elList = doc.getElementsByAttributeValueContaining("id", "soupiska"); for (int j = 0; j < 3; j++) { elList = posNum.get(j).getElementsByAttributeValueContaining("id", "soupiska"); for (Element item : elList) { String[] secondName = item.child(2).text().split(" "); if (duplicity.contains(item.child(2).text())) continue; duplicity.add(item.child(2).text()); try (Connection conn = ds.getConnection()) { try (PreparedStatement st = conn.prepareStatement(sql)) { st.setString(1, item.child(2).text()); String[] age = item.child(4).text().split(" "); st.setInt(2, Integer.parseInt(age[0])); String[] height = item.child(5).text().split(" "); st.setInt(3, Integer.parseInt(height[0])); String[] weight = item.child(6).text().split(" "); st.setInt(4, Integer.parseInt(weight[0])); try { st.setInt(5, Integer.parseInt(item.child(0).text())); } catch (NumberFormatException ex) { st.setInt(5, 0); } st.setInt(6, j); st.setInt(7, playerID); int addedRows = st.executeUpdate(); playerID++; } } catch (SQLException ex) { throw new SQLException(ex.getMessage(), ex.fillInStackTrace()); } } } } }