Example usage for org.jsoup.nodes Element toString

List of usage examples for org.jsoup.nodes Element toString

Introduction

In this page you can find the example usage for org.jsoup.nodes Element toString.

Prototype

public String toString() 

Source Link

Document

Gets this node's outer HTML.

Usage

From source file:com.ufukuzun.myth.dialect.bean.Myth.java

public <T> AjaxResponse response(AjaxRequest<T> form, String viewName, ModelMap modelMap,
        HttpServletResponse response, HttpServletRequest request) {
    AjaxResponse ajaxResponse = new AjaxResponse();

    for (RequestUpdate eachRequestUpdate : form.getUpdate()) {
        if (StringUtils.isNotBlank(eachRequestUpdate.getRenderFragment())) {
            String decodedRenderFragment = new String(
                    Base64.decodeBase64(eachRequestUpdate.getRenderFragment()));
            if (StringUtils.isNotBlank(decodedRenderFragment) && !eachRequestUpdate.getUpdates().isEmpty()) {
                String processResult = process(viewName, decodedRenderFragment, modelMap, request, response);
                Document document = parse(processResult);
                for (String eachId : eachRequestUpdate.getUpdates()) {
                    Element element = document.getElementById(eachId);
                    String content = element != null ? element.toString() : "";
                    ajaxResponse.add(eachId, content);
                }//from  w w  w . ja  va  2s. com
            }
        }
    }

    return ajaxResponse;
}

From source file:org.manalith.ircbot.plugin.linuxpkgfinder.DebianPackageFinder.java

public String find(String url, String commandName) {
    String result = "";
    boolean hasExacthits = false;

    try {/* w w  w.ja  v a  2s .  c  om*/

        Connection conn = Jsoup.connect(url);
        conn.timeout(20000);
        Document doc = conn.get();

        if (doc.select("#psearchres").size() == 0) {
            result = "[" + commandName + "]  ";
            return result;
        }

        Elements hits = doc.select("#psearchres").select("h2");
        int hsize = hits.size();

        if (hsize == 0)
            result = "[" + commandName + "]  ";
        for (int i = 0; i < hsize; i++) {
            if (hits.get(i).text().equals("Exact hits")) {
                hasExacthits = true;
                break;
            }

        }
        if (!hasExacthits) {
            result = "[" + commandName + "]  ";
            return result;
        }

        String pkgname = doc.select("#psearchres").select("h3").get(0).text().split("\\s")[1];

        Elements exactHits = doc.select("#psearchres").select("ul").get(0).select("li");
        int elemCnt = exactHits.size();
        Element latestElement = exactHits.get(elemCnt - 1);
        String description = latestElement.toString().split("<br>")[0].split("\\:")[1].trim();

        result = "[" + commandName + "] \u0002" + pkgname + "\u0002 - " + description + ", ";
        result += parseVersionInfo(doc) + ".";
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        result = ": " + e.getMessage();
    }

    return result;
}

From source file:web.analyzer.utils.Utils.java

public boolean hasLoginForm(Document doc) {
    Elements formElements = doc.getElementsByTag("form");
    for (Element formElement : formElements) {

        String frmElementAsString = formElement.toString().toLowerCase().replace("'", "\"");
        Pattern inputTextTagPattern = Pattern.compile("type=\"text\"");
        Matcher inputTextTagMatcher = inputTextTagPattern.matcher(frmElementAsString);
        int inputTextTagCount = 0;
        while (inputTextTagMatcher.find()) {
            inputTextTagCount++;/*from   w  ww . j  a  v a  2 s .  co m*/
        }

        Pattern inputEmailTagPattern = Pattern.compile("type=\"email\"");
        Matcher inputEmailTagMatcher = inputEmailTagPattern.matcher(frmElementAsString);
        int inputEmailTagCount = 0;
        while (inputEmailTagMatcher.find()) {
            inputEmailTagCount++;
        }

        Pattern inputPasswordTagPattern = Pattern.compile("type=\"password\"");
        Matcher inputPasswordTagMatcher = inputPasswordTagPattern.matcher(frmElementAsString);
        int inputPasswordTagCount = 0;
        while (inputPasswordTagMatcher.find()) {
            inputPasswordTagCount++;
        }

        if ((inputTextTagCount == 1 || inputEmailTagCount == 1) && inputPasswordTagCount == 1) {
            return true;
        }
    }

    return false;
}

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.  j a  v  a2  s  .  com*/
        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:net.poemerchant.scraper.ShopScraper.java

public String scrapeIGN() {
    Element forumTable = doc.select("table.forumTable.forumPostListTable").select("div.content").first();
    String bigDivContentString = forumTable.toString();
    ign = RegexUtils.extract(bigDivContentString, "My\\sIGN\\sis\\s\\b(.*)\\b", 1, true);
    return ign;//  w  w  w .ja  v a2 s.co  m
}

From source file:com.gote.downloader.kgs.KGSDownloader.java

/**
 * Try to found out if a game has been already played or by looking into archives page by page.
 * //w  w w . j av a 2  s  .  com
 * @param pGame Game to found and update
 * @param pPlayerArchivePages List of archive pages
 */
private void retrieveAndUpdateGame(Game pGame, List<Document> pPlayerArchivePages) {
    stage = "Etape 3/3 - Rcupration de la partie";
    for (Document playerArchivePage : pPlayerArchivePages) {
        Elements tableRows = playerArchivePage.select("tr");

        for (Element row : tableRows) {
            if (Pattern.matches(regexGame, row.toString())) {
                // LOGGER.log(Level.INFO, "[TRACE] New row checked " + row.toString());

                // "Visible", "Blanc", "Noir", "Genre", "Debutee le", "Type", "Resultat"
                Elements tableCells = row.getElementsByTag("td");

                String gameUrl = isPublicGame(tableCells.get(GAMEURL));

                // May check with time if you can leave or continue
                if (gameUrl != null && !gameUrl.isEmpty()) {
                    if (gameUrl.toLowerCase().contains(pGame.getBlack().getPseudo().toLowerCase())
                            && gameUrl.toLowerCase().contains(pGame.getWhite().getPseudo().toLowerCase())) {
                        pGame.setGameUrl(gameUrl);
                        pGame.setResult(getStdResultFromKGSResult(tableCells.get(RESULT).text()));
                        File sgf = new File(AppUtil.PATH_TO_TOURNAMENTS + tournament.getTitle() + "/"
                                + AppUtil.PATH_TO_SGFS + tournament.getTitle().trim() + "_round"
                                + pGame.getBlack().getPseudo() + "_" + pGame.getWhite().getPseudo() + ".sgf");
                        try {
                            URL url = new URL(gameUrl);
                            FileUtils.copyURLToFile(url, sgf);
                        } catch (MalformedURLException e) {
                            log(Level.WARNING, "URL " + gameUrl + " malformee", e);
                        } catch (IOException e) {
                            log(Level.WARNING, "Erreur lors de l'ecriture du fichier", e);
                        }

                        // Leave the process
                        return;
                    }
                } else {
                    log(Level.INFO, "La partie " + tableCells
                            + " n'est pas visible ou un probleme a eu lieu lors de la recuperation de l'url");
                }
            }
        }
    }
}

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 {/*ww w  . j av  a  2 s  . co  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:tkbautobooking.BookingSystem.java

private void praseBookingToken() throws Exception {

    Document doc = Jsoup.parse(BookingPageHTML);
    Element script = doc.getElementsByTag("script").last();

    String str = script.toString().substring(script.toString().indexOf("access_token"));
    str = str.substring(str.indexOf("\"") + 1);
    str = str.substring(0, str.indexOf("\""));

    booking_hidden_token = str;//w ww .j  a  v  a2s  . co m
}

From source file:net.liuxuan.Tools.signup.SignupV2ex.java

public void getLoginForm() throws IOException {

    HttpGet httpget = new HttpGet("http://v2ex.com/signin");
    CloseableHttpResponse response1 = httpclient.execute(httpget);
    try {/*from  w  w  w .ja v  a 2s.co 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:mobi.jenkinsci.ci.client.JenkinsClient.java

private HashMap<String, Issue> getIssuesFromTable(final Element changesTable) {
    final HashMap<String, Issue> issues = new HashMap<String, ChangeSetItem.Issue>();
    if (changesTable == null) {
        return issues;
    }/*from  ww  w  . j  a v a2 s .c  o  m*/

    if (changesTable.children().size() <= 0) {
        LOG.warn("Cannot find changes TBODY");
        return issues;
    }

    final Element tbody = changesTable.child(0);
    final Elements rows = tbody.children();
    for (final Element row : rows) {
        final String commitId = getCommitIdFromRow(row);
        Issue issue;
        try {
            issue = getIssueFromRow(row);
            if (issue != null) {
                issues.put(commitId, issue);
            }
        } catch (final MalformedURLException e) {
            LOG.warn("Invalid issue URL for row " + row.toString() + ": skipping", e);
        }
    }

    return issues;
}