Example usage for org.jsoup.nodes Document getElementsByAttribute

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

Introduction

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

Prototype

public Elements getElementsByAttribute(String key) 

Source Link

Document

Find elements that have a named attribute set.

Usage

From source file:webcralwerproject1.Webcrawler.java

public String writeContent(Document htmlDocument) {// throws IOException {
    FileWriter fWriter = null;//from  w  w  w .  j a v  a 2 s.co  m
    BufferedWriter writer = null;
    String path = null;
    try {
        File file = new File(DirectoryName + "/" + crawlcount);
        if (!file.exists()) {
            if (file.mkdir()) {
                System.out.println("Repository Directory is created!");
            } else {
                System.out.println("Failed to create directory!");
            }
        }
        File f = new File(file.getAbsolutePath() + "/" + MaxPage + "file.html");
        path = f.getAbsolutePath();
        Elements img = htmlDocument.getElementsByTag("img");
        Elements srcc = htmlDocument.getElementsByAttribute("src");
        for (Element el : img) {
            imagecount++;
            el.attr("src", "a");
        }
        // System.out.println("Imagecount : " + imagecount );
        FileUtils.writeStringToFile(f, htmlDocument.html(), "UTF-8");

    } catch (Exception e) {
        System.out.println("Inside writeContent Exception " + e);
    }
    System.out.println("Inside writeContent ");
    return path;
}