Example usage for org.jsoup.nodes Document getElementById

List of usage examples for org.jsoup.nodes Document getElementById

Introduction

In this page you can find the example usage for org.jsoup.nodes Document getElementById.

Prototype

public Element getElementById(String id) 

Source Link

Document

Find an element by ID, including or under this element.

Usage

From source file:io.github.carlomicieli.footballdb.starter.parsers.DraftParser.java

protected Optional<Element> picksTable(Document doc) {
    return Optional.ofNullable(doc.getElementById("drafts"));
}

From source file:goofyhts.torrentkinesis.test.HttpTest.java

@Test
public void testGet() {
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        HttpClientContext context = new HttpClientContext();
        CredentialsProvider credProv = new BasicCredentialsProvider();
        credProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("root", "Whcinhry21#"));
        context.setCredentialsProvider(credProv);
        HttpGet httpGet = new HttpGet("http://localhost:8150/gui/token.html");

        CloseableHttpResponse response = client.execute(httpGet, context);
        String responseBody = IOUtils.toString(response.getEntity().getContent());
        System.out.println(responseBody);
        Document doc = Jsoup.parse(responseBody);
        System.out.println(doc.getElementById("token").text());
    } catch (ClientProtocolException e) {
        e.printStackTrace();//  w w w .  j av  a2 s .  co  m
    } catch (IOException e) {
        e.printStackTrace();
    }
    //Assert.assertTrue(true);
}

From source file:jobhunter.infoempleo.Client.java

private String getCompany(final Document doc) {
    Element el = doc.getElementById("ctl00_CPH_Body_Logo_Empresa");
    return el != null ? el.attr("title") : "";
}

From source file:com.cognifide.aet.job.common.datafilters.extractelement.ExtractElementDataModifier.java

private String modifyDataForElementParam(Document document) throws ProcessingException {
    String result;//ww w. j  a va2  s  .com
    Element element = document.getElementById(elementId);
    if (element != null) {
        result = element.outerHtml();
    } else {
        throw new ProcessingException("No element with id=" + elementId + " found!");
    }
    return result;
}

From source file:HttpCilentExample.HttpCilentExample.java

public List<NameValuePair> getFormParams(String html, String username, String password)
        throws UnsupportedEncodingException {

    System.out.println("Extracting form's data...");

    Document doc = Jsoup.parse(html);

    // Google form id
    Element loginform = doc.getElementById("gaia_loginform");
    Elements inputElements = loginform.getElementsByTag("input");

    List<NameValuePair> paramList = new ArrayList<NameValuePair>();

    for (Element inputElement : inputElements) {
        String key = inputElement.attr("name");
        String value = inputElement.attr("value");

        if (key.equals("Email"))
            value = username;/*from   w  w  w . j a  v  a 2 s. c  o m*/
        else if (key.equals("Passwd"))
            value = password;

        paramList.add(new BasicNameValuePair(key, value));

    }

    return paramList;
}

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 {//from   w  w  w  .j  a 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;
}

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 {//w  ww. j av a2 s .  c o  m
            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.liato.bankdroid.banking.banks.Nordnet.java

@Override
protected LoginPackage preLogin() throws BankException, ClientProtocolException, IOException {
    urlopen = new Urllib(context, CertificateReader.getCertificates(context, R.raw.cert_nordnet));
    urlopen.setContentCharset(HTTP.ISO_8859_1);
    response = urlopen.open("https://www.nordnet.se/mux/login/startSE.html");

    Document d = Jsoup.parse(response);
    Element e = d.getElementById("input1");
    if (e == null || "".equals(e.attr("name"))) {
        throw new BankException(res.getText(R.string.unable_to_find).toString() + " username field.");
    }//from w w  w  . j a va2  s .c o m
    String loginFieldName = e.attr("name");
    e = d.getElementById("pContHidden");
    if (e == null || "".equals(e.attr("name"))) {
        throw new BankException(res.getText(R.string.unable_to_find).toString() + " password field.");
    }
    String loginFieldPassword = e.attr("name");

    List<NameValuePair> postData = new ArrayList<NameValuePair>();
    postData.add(new BasicNameValuePair("checksum", ""));
    postData.add(new BasicNameValuePair("referer", ""));
    postData.add(new BasicNameValuePair("encryption", "0"));
    postData.add(new BasicNameValuePair(loginFieldName, username));
    postData.add(new BasicNameValuePair(loginFieldPassword, password));

    return new LoginPackage(urlopen, postData, response, "https://www.nordnet.se/mux/login/login.html");
}

From source file:com.liato.bankdroid.banking.banks.Hors.java

@Override
protected LoginPackage preLogin() throws BankException, IOException {
    urlopen = new Urllib(context);
    urlopen.setAllowCircularRedirects(true);
    response = urlopen.open("https://www.dittkort.se//q/?p=7EB4F129-0A41-417F-8FEA-51B2B75B9D24");

    Document d = Jsoup.parse(response);
    Element e = d.getElementById("__VIEWSTATE");
    if (e == null || e.attr("value") == null) {
        throw new BankException(res.getText(R.string.unable_to_find).toString() + " ViewState.");
    }//  ww w.j  a va 2 s  .co m
    String viewState = e.attr("value");

    e = d.getElementById("__EVENTVALIDATION");
    if (e == null || e.attr("value") == null) {
        throw new BankException(res.getText(R.string.unable_to_find).toString() + " EventValidation.");
    }
    String eventValidation = e.attr("value");

    List<NameValuePair> postData = new ArrayList<NameValuePair>();
    postData.add(new BasicNameValuePair("__EVENTTARGET", ""));
    postData.add(new BasicNameValuePair("__EVENTARGUMENT", ""));
    postData.add(new BasicNameValuePair("__VIEWSTATE", viewState));
    postData.add(new BasicNameValuePair("__VIEWSTATEGENERATOR", "D7823E0B"));
    postData.add(new BasicNameValuePair("__EVENTVALIDATION", eventValidation));
    postData.add(new BasicNameValuePair("_ctl0:cphMain:SmartpassTextbox", getUsername()));
    postData.add(new BasicNameValuePair("_ctl0:cphMain:SubmitButton", "OK"));
    postData.add(new BasicNameValuePair("_ctl0:cphMain:chbRememberSmartPassCode", "on"));
    postData.add(new BasicNameValuePair("_ctl0:cphMain:cookieEnabled", "true"));
    return new LoginPackage(urlopen, postData, response,
            "https://www.dittkort.se//q/?p=7EB4F129-0A41-417F-8FEA-51B2B75B9D24");
}

From source file:com.liato.bankdroid.banking.banks.Bioklubben.java

@Override
protected LoginPackage preLogin() throws BankException, ClientProtocolException, IOException {
    urlopen = new Urllib(context, CertificateReader.getCertificates(context, R.raw.cert_bioklubben));
    urlopen.setAllowCircularRedirects(true);
    response = urlopen.open("http://bioklubben.sf.se/Start.aspx");

    Document d = Jsoup.parse(response);
    Element e = d.getElementById("__VIEWSTATE");
    if (e == null || e.attr("value") == null) {
        throw new BankException(res.getText(R.string.unable_to_find).toString() + " ViewState.");
    }/* www .j a v  a  2  s  .  co m*/
    String viewState = e.attr("value");

    e = d.getElementById("__EVENTVALIDATION");
    if (e == null || e.attr("value") == null) {
        throw new BankException(res.getText(R.string.unable_to_find).toString() + " EventValidation.");
    }
    String eventValidation = e.attr("value");

    List<NameValuePair> postData = new ArrayList<NameValuePair>();
    postData.add(
            new BasicNameValuePair("__EVENTTARGET", "ctl00$ContentPlaceHolder1$LoginUserControl$LogonButton"));
    postData.add(new BasicNameValuePair("__EVENTARGUMENT", ""));
    postData.add(new BasicNameValuePair("__VIEWSTATE", viewState));
    postData.add(new BasicNameValuePair("__EVENTVALIDATION", eventValidation));
    postData.add(new BasicNameValuePair("ctl00_toolkitscriptmanager_HiddenField", ""));
    postData.add(new BasicNameValuePair("ctl00$toolkitscriptmanager",
            "ctl00$UpdatePanel|ctl00$ContentPlaceHolder1$LoginUserControl$LogonButton"));
    postData.add(
            new BasicNameValuePair("ctl00$ContentPlaceHolder1$LoginUserControl$LoginNameTextBox", username));
    postData.add(
            new BasicNameValuePair("ctl00$ContentPlaceHolder1$LoginUserControl$PasswordTextBox", password));
    return new LoginPackage(urlopen, postData, response, "http://bioklubben.sf.se/Start.aspx");
}