List of usage examples for org.jsoup.nodes Element select
public Elements select(String cssQuery)
From source file:com.liato.bankdroid.banking.banks.Jojo.java
@Override public void update() throws BankException, LoginException, BankChoiceException { super.update(); if (username == null || password == null || username.length() == 0 || password.length() == 0) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); }/* w w w. j av a2 s .c om*/ urlopen = login(); Document d = Jsoup.parse(response); Elements es = d.select(".saldo_ok_wrapper > table > tbody tr"); if (es != null) { for (int i = 0; i < 2; i++) { int index = 0 + i; if (es.size() >= index) { Element e = es.get(index); Element name = e.select(".first").first(); Element amount = e.select(".right").first(); if (name != null && amount != null) { Account a = new Account(name.text().replaceAll(":", "").trim(), Helpers.parseBalance(amount.text()), Integer.toString(i)); accounts.add(a); balance = balance.add(a.getBalance()); } } } } if (accounts.isEmpty()) { throw new BankException(res.getText(R.string.no_accounts_found).toString()); } super.updateComplete(); }
From source file:de.geeksfactory.opacclient.apis.Zones.java
static List<LentItem> parseMediaList(Document doc) { List<LentItem> lent = new ArrayList<>(); DateTimeFormatter fmt = DateTimeFormat.forPattern("dd/MM/yyyy").withLocale(Locale.GERMAN); Pattern id_pat = Pattern.compile("javascript:renewItem\\('[0-9]+','(.*)'\\)"); Pattern cannotrenew_pat = Pattern.compile("javascript:CannotRenewLoan\\('[0-9]+','(.*)','[0-9]+'\\)"); for (Element table : doc .select(".LoansBrowseItemDetailsCellStripe table, " + ".LoansBrowseItemDetailsCell " + "table")) { LentItem item = new LentItem(); for (Element tr : table.select("tr")) { String desc = tr.select(".LoanBrowseFieldNameCell").text().trim(); String value = tr.select(".LoanBrowseFieldDataCell").text().trim(); if (desc.equals("Titel")) { item.setTitle(value);//from w w w .j a v a 2s.c o m if (tr.select(".LoanBrowseFieldDataCell a[href]").size() > 0) { String href = tr.select(".LoanBrowseFieldDataCell a[href]").attr("href"); Map<String, String> params = getQueryParamsFirst(href); if (params.containsKey("BACNO")) { item.setId(params.get("BACNO")); } } } if (desc.equals("Verfasser")) item.setAuthor(value); if (desc.equals("Mediennummer")) item.setBarcode(value); if (desc.equals("ausgeliehen in")) item.setHomeBranch(value); if (desc.matches("F.+lligkeits.*datum")) { value = value.split(" ")[0]; try { item.setDeadline(fmt.parseLocalDate(value)); } catch (IllegalArgumentException e) { e.printStackTrace(); } } } if (table.select(".button[Title~=Zum]").size() == 1) { Matcher matcher1 = id_pat.matcher(table.select(".button[Title~=Zum]").attr("href")); if (matcher1.matches()) item.setProlongData(matcher1.group(1)); } else if (table.select(".CannotRenewLink").size() == 1) { Matcher matcher = cannotrenew_pat.matcher(table.select(".CannotRenewLink").attr("href").trim()); if (matcher.matches()) { item.setProlongData("cannotrenew|" + matcher.group(1)); } item.setRenewable(false); } lent.add(item); } return lent; }
From source file:org.manalith.ircbot.plugin.linuxpkgfinder.DebianPackageFinder.java
public String parseVersionInfo(Document doc) { Elements exactHits = doc.select("#psearchres").select("ul").get(0).select("li"); String result = ""; for (Element e : exactHits) { String dist;/* ww w . ja v a 2 s .c o m*/ dist = e.select("a").text(); String version = " ?"; String[] versionLines = e.toString().split("<br>"); for (String line : versionLines) { String v = line.split(": ")[0]; if (v.split("\\s").length > 1) continue; else { version = v; break; } } if (result.length() != 0) result += ", "; result += "\u0002" + dist + "\u0002: " + version; } return result; }
From source file:zjut.soft.finalwork.fragment.PageFragment1.java
public void showLevelResult() { new Thread(new Runnable() { @Override// w w w. j a v a2 s. c om public void run() { try { HttpGet get = new HttpGet(((YCApplication) getActivity().getApplication()).get("selectedIp") + Constant.levelQuery); YCApplication app = (YCApplication) getActivity().getApplicationContext(); HttpResponse response = app.getClient().execute(get); HttpEntity entity = response.getEntity(); BufferedReader br = new BufferedReader( new InputStreamReader(entity.getContent(), Constant.ENCODING)); StringBuilder sb = new StringBuilder(); String temp = null; while ((temp = br.readLine()) != null) { sb.append(temp); } Document doc = Jsoup.parse(sb.toString()); Elements tables = doc.select("#DJKCJ"); if (tables.size() > 0) { Element table = tables.get(0); Elements trs = table.select("tr"); levelTest = new ArrayList<LevelTest>(); info = new StringBuilder(); if (trs.size() > 1) { for (int i = 1; i < trs.size(); i++) { LevelTest test = new LevelTest(); Element tr = trs.get(i); Elements tds = tr.select("td"); String name = tds.get(0).select("span").get(0).html(); String grade = tds.get(1).select("span").get(0).html(); String date = tds.get(2).select("span").get(0).html(); System.out.println(name + "," + grade + "," + date); info.append(name + "," + grade + "," + date + "\n"); test.setName(name); test.setGrade(grade); test.setDate(date); levelTest.add(test); } } } mHandler.post(new Runnable() { @Override public void run() { tv.setText(info.toString()); } }); } catch (Exception e) { e.printStackTrace(); } } }).start(); }
From source file:org.hmzb.test.HttpClientTest.java
@Test public final void testPMS() throws IOException { // Map<String, String> data = new HashMap<String, String>(); // data.put("act", "module"); // data.put("name", "sns"); // data.put("do", "post"); // data.put("id", "137"); // data.put("replyid", ""); // data.put("postid", "150"); // data.put("reply_content", "?, ?"); String url = "http://pms.local.17173.com/task_list_department.php?action=search&employment_id=&state=0&time_id=plan&start_date=2014-01-01&end_date=2014-05-16&x=24&y=5"; String cookieValue = "SUV=1381469482625841; NUV=1381507200000; sohutag=8HsmeSc5NCwmcyc5NCwmYjc5NCwmYSc5NCwmZjc5NCwmZyc5Njwmbjc5NCwmaSc5NCwmdyc5NCwmaCc5NCwmYyc5NCwmZSc5NCwmbSc5NH0; __utma=113262040.1666690635.1382600575.1382600575.1382600575.1; vjuids=c639cb6b1.142370b45c7.0.ef4cedbb; Hm_lvt_0245ebe4fb30a09e371e4f011dec1f6a=1388137801; live_17173_unique=e7de7aed49953586fc1da607967cf847; _ga=GA1.2.1666690635.1382600575; pgv_pvi=2611450780; vjlast=1383902955.1399958818.22; ermpdockData=1,2,4,13,17; DIFF=1400117702510; IPLOC=CN3501; ErmpToken=Q1k1MzIw; ErmpTicket=MTAuNS4xNS4xNg; ppinf=2|1401269453|1402479053|bG9naW5pZDowOnx1c2VyaWQ6MTY6cHR6aHVmQDE3MTczLmNvbXxzZXJ2aWNldXNlOjMwOjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMHxjcnQ6MTA6MjAxMi0xMS0yMHxlbXQ6MTowfGFwcGlkOjQ6MTA3N3x0cnVzdDoxOjF8cGFydG5lcmlkOjE6MHxyZWxhdGlvbjowOnx1dWlkOjE2OmRiYmNhNTA3ZjNmMjRjMnR8dWlkOjk6czg3MDM4OTcwfHVuaXFuYW1lOjQ0OiVFNiU5MCU5QyVFNyU4QiU5MCVFNyVCRCU5MSVFNSU4RiU4QjMxNDI4NjcxfA; pprdig=Hs7tIw6klJdNasYa5mYo4aOzZnr2dL96PkIAMo8K4KGp4UM2yhx2LHuNOZ5zX7s4pKShi4GnXYFIIyAW-BWRJCAgmI2qeorvqshYjT5gs4gWKGgJNtoQAbdIt1liIK-Bt1aX_mYueEHUA_yRDVhRxRVLVt3mtlgywukd-stCIOE; lastdomain=1402479053|cHR6aHVmQDE3MTczLmNvbXw|17173.com; PHPSESSID=qcr7raandp6l0k7g9vpg0lgn22; PMS_cypms_username=fuzhu; PMS_cypms_auth=c0b47dad95a0e7ef7505d9ce057b6651"; Document resultDoc = Jsoup.connect(url).header("cookie", cookieValue).timeout(20000).get(); Elements table = resultDoc.select("table.list"); Elements trs = table.select("tr"); // // w ww.ja va 2s . c om trs.remove(0); // ?? trs.remove(trs.size() - 1); // Double totalTime = 0d; String regex = ".*?.*"; for (Element element : trs) { Elements tds = element.select("td"); // System.out.println(tds); String projectName = tds.get(3).text(); Double realTime = Double.valueOf(tds.get(7).text()); if (projectName.matches(regex)) { totalTime += realTime; } } System.out.println(totalTime); }
From source file:hu.petabyte.redflags.engine.gear.parser.MetadataParser.java
public Notice parseDataTab(Notice notice, Document dataTab) { Data data = notice.getData(); notice.setCancelled(!dataTab.select("div#cancelDoc").isEmpty()); for (Element tr : dataTab.select("table.data tr")) { String field = tr.select("th").first().text(); String value = JsoupUtils.text(tr.select("td").last()); LOG.trace("{} data: {} = {}", notice.getId(), field, value); setDataField(data, field, value); }/*from ww w. ja v a 2s . co m*/ return notice; }
From source file:me.vertretungsplan.parser.TurboVertretungParser.java
private void parseTurboVertretungDay(SubstitutionSchedule v, Document doc) { SubstitutionScheduleDay day = new SubstitutionScheduleDay(); String date = doc.select(".Titel").text().replaceFirst("Vertretungsplan( fr)? ", ""); day.setDate(DateTimeFormat.forPattern("EEEE, d. MMMM yyyy").withLocale(Locale.GERMAN).parseLocalDate(date)); String lastChange = doc.select(".Stand").text().replace("Stand: ", ""); day.setLastChange(DateTimeFormat.forPattern("dd.MM.yyyy HH:mm:ss").withLocale(Locale.GERMAN) .parseLocalDateTime(lastChange)); if (doc.text().contains("Kein Vertretungsplan")) { v.addDay(day);//w w w. jav a 2s . c o m return; } if (doc.select(".LehrerFrueher").size() > 0) { day.addMessage(doc.select(".LehrerFrueherLabel").text() + "\n" + doc.select(".LehrerFrueher").text()); } if (doc.select(".LehrerVerplant").size() > 0) { day.addMessage(doc.select(".LehrerVerplantLabel").text() + "\n" + doc.select(".LehrerVerplant").text()); } if (doc.select(".Abwesenheiten-Klassen").size() > 0) { day.addMessage(doc.select(".Abwesenheiten-KlassenLabel").text() + "\n" + doc.select(".Abwesenheiten-Klassen").text()); } Element table = doc.select("table").first(); for (Element row : table.select("tr:has(td)")) { Substitution substitution = new Substitution(); substitution.setLesson(row.select(query("Stunde")).text()); substitution.setPreviousTeacher(row.select(query("Lehrer")).text()); substitution.setTeacher(row.select(query("Vertretung")).text()); substitution.setClasses(new HashSet<>(Arrays.asList(row.select(query("Klasse")).text().split(" ")))); substitution.setSubject(row.select(query("Fach")).text()); substitution.setDesc(row.select(query("Anmerkung")).text()); substitution.setRoom(row.select(query("Raum")).text()); String type = recognizeType(row.select(query("Anmerkung")).text()); if (type == null) type = "Vertretung"; substitution.setType(type); substitution.setColor(colorProvider.getColor(type)); day.addSubstitution(substitution); } v.addDay(day); }
From source file:com.josue.lottery.eap.service.core.LotoImporter.java
private void parseHtml(File file) { // String html = "<html><head><title>First parse</title></head>" // + "<body><p>Parsed HTML into a doc.</p>" // +/*from w ww .ja v a2s. co m*/ // " <table><tr><td>satu</td><td>satu-1</td></tr><tr><td>dua</td><td>dua-1</td></tr><tr><td>tiga</td><td>tiga-1</td></tr></table> " // + "</body></html>"; StringBuilder sb = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new FileReader(file)); } catch (FileNotFoundException ex) { java.util.logging.Logger.getLogger(LotoImporter.class.getName()).log(Level.SEVERE, null, ex); } String line; try { while ((line = br.readLine()) != null) { sb.append(line); } } catch (IOException ex) { java.util.logging.Logger.getLogger(LotoImporter.class.getName()).log(Level.SEVERE, null, ex); } Document doc = Jsoup.parse(sb.toString()); Element table = doc.select("table").first(); Iterator<Element> iterator = table.select("td").iterator(); while (iterator.hasNext()) { logger.info("text : " + iterator.next().text()); } String title = doc.title(); System.out.println("Document title : " + title); }
From source file:com.liato.bankdroid.banking.banks.AbsIkanoPartner.java
@Override public void update() throws BankException, LoginException, BankChoiceException { super.update(); if (username == null || password == null || username.length() == 0 || password.length() == 0) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); }// w ww. j a v a 2 s . c o m urlopen = login(); Document d = Jsoup.parse(response); Element element = d.select("#primary-nav > li:eq(1) > a").first(); if (element != null && element.attr("href") != null) { String myAccountUrl = element.attr("href"); try { response = urlopen.open("https://partner.ikanobank.se/" + myAccountUrl); d = Jsoup.parse(response); Elements es = d.select("#CustomerAccountInformationSpan > span > span"); int accId = 0; for (Element el : es) { Element name = el.select("> span > span:eq(0)").first(); Element balance = el.select("> span:eq(1)").first(); Element currency = el.select("> span:eq(2)").first(); if (name != null && balance != null && currency != null) { Account account = new Account(name.text().trim(), Helpers.parseBalance(balance.text()), Integer.toString(accId)); account.setCurrency(Helpers.parseCurrency(currency.text(), "SEK")); if (accId > 0) { account.setAliasfor("0"); } accounts.add(account); accId++; } } if (accounts.isEmpty()) { throw new BankException(res.getText(R.string.no_accounts_found).toString()); } // Use the amount from "Kvar att handla fr" which should be the // last account in the list. this.balance = accounts.get(accounts.size() - 1).getBalance(); ArrayList<Transaction> transactions = new ArrayList<Transaction>(); es = d.select("#ShowCustomerTransactionPurchasesInformationDiv table tr:has(td)"); for (Element el : es) { if (el.childNodeSize() == 6) { Transaction transaction = new Transaction(el.child(0).text().trim(), el.child(1).text().trim(), Helpers.parseBalance(el.child(2).text())); transaction.setCurrency(Helpers.parseCurrency(el.child(3).text().trim(), "SEK")); transactions.add(transaction); } } accounts.get(0).setTransactions(transactions); } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } } if (accounts.isEmpty()) { throw new BankException(res.getText(R.string.no_accounts_found).toString()); } super.updateComplete(); }
From source file:hu.petabyte.redflags.engine.gear.parser.DocFamilyFetcher.java
public Notice parseDocFamilyTab(Notice notice, Document docFamilyTab) { for (Element memberTable : docFamilyTab.select("table.family")) { try {//from w w w. j av a2s .c o m NoticeID memberId = new NoticeID( memberTable.select("thead a[href~=TED:NOTICE:]").first().text().split(":", 2)[0]); if (!notice.getId().equals(memberId)) { Notice memberNotice = new Notice(memberId); Elements tds = memberTable.select("tbody tr").first().select("td.bgGreen"); String rawMemberPubDate = tds.get(0).text(); Date memberPubDate = new SimpleDateFormat(DATE_FORMAT).parse(rawMemberPubDate); memberNotice.getData().setPublicationDate(memberPubDate); if (tds.size() > 1) { String rawMemberDeadline = tds.get(1).text(); Date memberDeadline = new SimpleDateFormat(DATE_FORMAT).parse(rawMemberDeadline); memberNotice.getData().setDeadline(memberDeadline); } notice.getFamilyMembers().add(memberNotice); LOG.trace("{} Member found: {} - {} (deadline: {})", notice.getId(), memberId, memberPubDate, memberNotice.getData().getDeadline()); } } catch (Exception e) { LOG.warn("Cannot parse a document family member of notice " + notice.getId(), e); } } return notice; }