List of usage examples for org.jsoup.nodes Element attr
public String attr(String attributeKey)
From source file:com.liato.bankdroid.banking.banks.Volvofinans.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 a v a 2 s.c o m*/ urlopen = login(); String response = null; try { response = urlopen .open("https://inloggad.volvofinans.se/privat/kund/kortkonto/oversikt/kortkonton.html"); try { JSONObject object = (JSONObject) new JSONTokener(response).nextValue(); JSONArray data = object.getJSONArray("data"); int length = data.length(); for (int index = 0; index < length; index++) { JSONObject account = data.getJSONObject(index); Document d = Jsoup.parse(account.getString("namnUrl")); Element e = d.getElementsByTag("a").first(); if (e != null && e.attr("href") != null) { mAccountUrlMappings.put(account.getString("kontonummer"), e.attr("href").replace("/info.html", "/info/kontoutdrag.html")); } accounts.add(new Account( String.format("%s (%s)", account.getString("namn"), account.getString("kontonummer")), Helpers.parseBalance(account.getString("disponibeltBelopp")) .subtract(Helpers.parseBalance(account.getString("limit"))), account.getString("kontonummer"))); } } catch (JSONException e) { throw new BankException(e.getMessage()); } if (accounts.isEmpty()) { throw new BankException(res.getText(R.string.no_accounts_found).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } finally { super.updateComplete(); } }
From source file:com.github.jrrdev.mantisbtsync.core.common.auth.request.AuthHttpPost.java
/** * {@inheritDoc}//from w ww . ja v a 2s. co m * */ @Override public void configFromPreviousResponse(final HttpEntity entity) throws ParseException, IOException { if (formAction == null || entity == null) { return; } final String content = EntityUtils.toString(entity); final Elements forms = Jsoup.parse(content).getElementsByTag(HTML_FORM); for (final Element form : forms) { // Get the form if (form.hasAttr(HTML_ACTION) && formAction.equalsIgnoreCase(form.attr(HTML_ACTION))) { // Parsing of hidden inputs final Elements inputs = form.getElementsByTag(HTML_INPUT); for (final Element input : inputs) { if (input.hasAttr(HTML_TYPE) && HTML_HIDDEN.equalsIgnoreCase(input.attr(HTML_TYPE))) { final String value = input.attr(HTML_VALUE); final String name = input.attr(HTML_NAME); builder = builder.addParameter(name, value); } } break; } } }
From source file:es.logongas.util.seguridad.AuthenticationProviderImplMoodle.java
@Override public Principal authenticate(Credential credential) { try {/* ww w . j av a 2 s . com*/ StrongPasswordEncryptor passwordEncryptor = new StrongPasswordEncryptor(); if ((credential instanceof CredentialImplLoginPassword) == false) { return null; } CredentialImplLoginPassword credentialImplLoginPassword = (CredentialImplLoginPassword) credential; if (loginAdmin.equalsIgnoreCase(credentialImplLoginPassword.getLogin())) { if (passwordEncryptor.checkPassword(credentialImplLoginPassword.getPassword(), passwordAdmin) == false) { return null; } } else { HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); DefaultHttpClient httpClientPost = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(moodleLoginURL); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("username", credentialImplLoginPassword.getLogin())); nvps.add(new BasicNameValuePair("password", credentialImplLoginPassword.getPassword())); httpPost.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response1 = httpClientPost.execute(httpPost); InputStream inputStream = response1.getEntity().getContent(); Document document = Jsoup.parse(inputStreamToString(inputStream)); Elements divElements = document.getElementsByClass("logininfo"); if (divElements.size() == 0) { return null; } Element divElement = divElements.get(0); Elements aElements = divElement.getElementsByTag("a"); if (aElements.size() == 0) { return null; } Element aElement = aElements.get(aElements.size() - 1); if (aElement.attr("href").indexOf("logout") < 0) { return null; } DefaultHttpClient httpclient2 = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(aElement.attr("href")); httpclient2.execute(httpGet); } GenericDAO<Identity, Integer> genericDAO = daoFactory.getDAO(Identity.class); Identity identity = genericDAO.readByNaturalKey(credentialImplLoginPassword.getLogin()); return identity; } catch (BusinessException ex) { return null; } catch (Exception ex) { log.info("Fallo al conectarse al moodle", ex); throw new RuntimeException(ex); } }
From source file:br.gov.jfrj.siga.base.SigaHTTP.java
private String getAttributeValueFromHtml(String htmlContent, String attribute) { String value = ""; Document doc = Jsoup.parse(htmlContent); // Get SAMLRequest value for (Element el : doc.select("input")) { if (el.attr("name").equals(attribute)) { value = el.attr("value"); }//from w ww .j a va 2 s . c om } return value; }
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()); }//from ww w .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:io.seldon.importer.articles.dynamicextractors.CategoryFromKeywordsDynamicExtractor.java
@Override public String extract(AttributeDetail attributeDetail, String url, Document articleDoc) throws Exception { String attrib_value = null;//from w w w. java 2s . co m String[] tags = null; if ((attributeDetail.extractor_args != null) && (attributeDetail.extractor_args.size() >= 3)) { String cssSelector = attributeDetail.extractor_args.get(0); Element element = articleDoc.select(cssSelector).first(); if (StringUtils.isNotBlank(cssSelector)) { String value_name = attributeDetail.extractor_args.get(1); if (element != null && element.attr(value_name) != null) { String rawList = element.attr(value_name); if (StringUtils.isNotBlank(rawList)) { tags = rawList.split(","); for (int i = 0; i < tags.length; i++) { tags[i] = tags[i].trim().toLowerCase(); } attrib_value = StringUtils.join(tags, ','); } } } } if (StringUtils.isNotBlank(attrib_value)) { String[] categories = attributeDetail.extractor_args.get(2).split(","); for (String category : categories) { for (String tag : tags) if (category.equals(tag)) return tag; } } return null; }
From source file:net.liuxuan.Tools.signup.SignupQjvpn.java
public void getLoginForm() throws IOException { HttpGet httpget = new HttpGet("http://www.qjvpn.com/user/login.php"); CloseableHttpResponse response1 = httpclient.execute(httpget); try {/* w w w. j av a 2 s. c o m*/ HttpEntity entity = response1.getEntity(); //?once String content = EntityUtils.toString(entity); // System.out.println(content); System.out.println("--------------"); System.out.println("--------------"); Document doc = Jsoup.parse(content); // Elements inputs = doc.select("input[type=text]"); Elements inputs = doc.select("input[type=hidden]"); for (int i = 0; i < inputs.size(); i++) { Element element = inputs.get(i); params.add(new BasicNameValuePair(element.attr("name"), element.attr("value"))); // params.put(element.attr("name"), element.attr("value")); System.out.println(element.toString()); System.out.println(element.attr("name")); System.out.println(element.attr("value")); } System.out.println("--------------"); System.out.println("--------------"); System.out.println("--------------"); System.out.println("--------------"); System.out.println("Login form get: " + response1.getStatusLine()); EntityUtils.consume(entity); System.out.println("Initial set of cookies:"); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } finally { response1.close(); } // HttpUriRequest login = RequestBuilder.post() // .setUri(new URI("http://v2ex.com/signin")) // .addParameter("u", "mosliu") // .addParameter("p", "mosesmoses") // .build(); // CloseableHttpResponse response2 = httpclient.execute(login); // try { // HttpEntity entity = response2.getEntity(); // // System.out.println("Login form get: " + response2.getStatusLine()); // // EntityUtils.consume(entity); // // System.out.println("Post logon cookies:"); // List<Cookie> cookies = cookieStore.getCookies(); // if (cookies.isEmpty()) { // System.out.println("None"); // } else { // for (int i = 0; i < cookies.size(); i++) { // System.out.println("- " + cookies.get(i).toString()); // } // } // // // // } finally { // response2.close(); // } // // // httpget = new HttpGet("http://v2ex.com/signin"); // response1 = httpclient.execute(httpget); // try { // HttpEntity entity = response1.getEntity(); // String content = EntityUtils.toString(entity); // System.out.println("-----------------content---------------------"); // System.out.println(content); // // EntityUtils.consume(entity); // } finally { // response1.close(); // } // // }
From source file:net.sf.jabref.logic.fetcher.ScienceDirect.java
@Override public Optional<URL> findFullText(BibEntry entry) throws IOException { Objects.requireNonNull(entry); Optional<URL> pdfLink = Optional.empty(); // Try unique DOI first Optional<DOI> doi = DOI.build(entry.getField("doi")); if (doi.isPresent()) { // Available in catalog? try {// w ww .j a va2s .com String sciLink = getUrlByDoi(doi.get().getDOI()); if (!sciLink.isEmpty()) { // Retrieve PDF link Document html = Jsoup.connect(sciLink).ignoreHttpErrors(true).get(); Element link = html.getElementById("pdfLink"); if (link != null) { LOGGER.info("Fulltext PDF found @ ScienceDirect."); pdfLink = Optional.of(new URL(link.attr("pdfurl"))); } } } catch (UnirestException e) { LOGGER.warn("ScienceDirect API request failed", e); } } return pdfLink; }
From source file:com.astrientlabs.nyt.NYT.java
public String extractImageURL(int session, String memberType, String name) throws IOException { String url = "http://memberguide.gpo.gov/" + session + "/" + memberType + "/" + name; try {//w w w . j a va2 s .c o m Connection c = Jsoup.connect(url); c.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.1) Gecko/20100101 Firefox/10.0.1"); Document doc = c.get(); doc.normalise(); Element content = doc.getElementById("ctl00_ContentPlaceHolder1_pic"); if (content != null) { String src = content.attr("src"); //System.out.println(src + " vs " + doc.baseUri()); if (src != null) { URL u = new URL("http://memberguide.gpo.gov/" + session + "/" + memberType + "/" + src); return u.toString(); } } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:net.sf.jabref.logic.fulltext.ScienceDirect.java
@Override public Optional<URL> findFullText(BibEntry entry) throws IOException { Objects.requireNonNull(entry); Optional<URL> pdfLink = Optional.empty(); // Try unique DOI first Optional<DOI> doi = entry.getFieldOptional(FieldName.DOI).flatMap(DOI::build); if (doi.isPresent()) { // Available in catalog? try {//from w w w . ja v a2 s .com String sciLink = getUrlByDoi(doi.get().getDOI()); if (!sciLink.isEmpty()) { // Retrieve PDF link Document html = Jsoup.connect(sciLink).ignoreHttpErrors(true).get(); Element link = html.getElementById("pdfLink"); if (link != null) { LOGGER.info("Fulltext PDF found @ ScienceDirect."); pdfLink = Optional.of(new URL(link.attr("pdfurl"))); } } } catch (UnirestException e) { LOGGER.warn("ScienceDirect API request failed", e); } } return pdfLink; }