Search in sources :

Example 66 with Element

use of org.jsoup.nodes.Element in project nixmash-blog by mintster.

the class JsoupUI method displayImports.

// endregion
// region non-used demos
private void displayImports() {
    Elements imports = doc.select("link[href]");
    print("\nImports: (%d)", imports.size());
    for (Element link : imports) {
        print(" * %s <%s> (%s)", link.tagName(), link.attr("abs:href"), link.attr("rel"));
    }
}
Also used : Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements)

Example 67 with Element

use of org.jsoup.nodes.Element in project nixmash-blog by mintster.

the class JsoupUI method getImages.

private List<JsoupImage> getImages(Document doc) {
    List<JsoupImage> images = new ArrayList<>();
    Elements elements;
    elements = doc.select("[src]");
    for (Element media : elements) {
        if (media.tagName().equals("img")) {
            JsoupImage img = new JsoupImage();
            img.setSrc(media.attr("abs:src"));
            img.setAlt(trim(media.attr("alt"), 60));
            img.setHeight(attrIntToNull(media.attr("height")));
            img.setWidth(attrIntToNull(media.attr("width")));
            images.add(img);
        }
    }
    return images;
}
Also used : JsoupImage(com.nixmash.blog.jsoup.base.JsoupImage) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Elements(org.jsoup.select.Elements)

Example 68 with Element

use of org.jsoup.nodes.Element in project nixmash-blog by mintster.

the class JsoupUI method displayLInks.

private void displayLInks() {
    Elements links = doc.select("a[href]");
    print("\nLinks: (%d)", links.size());
    for (Element link : links) {
        print(" * a: <%s>  (%s)", link.attr("abs:href"), trim(link.text(), 35));
    }
}
Also used : Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements)

Example 69 with Element

use of org.jsoup.nodes.Element in project nixmash-blog by mintster.

the class JsoupHtmlParser method parseMultipleLinks.

private List<JsoupLink> parseMultipleLinks(Field f) {
    List<JsoupLink> links = new ArrayList<>();
    Elements section;
    Elements elements;
    String css = f.getAnnotation(LinkSelector.class).value();
    if (css.length() > 0) {
        section = doc.select(css);
        if (section == null)
            return null;
        elements = section.first().select("a[href]");
    } else {
        elements = doc.select("a[href]");
    }
    for (Element element : elements) {
        if (element.tagName().equals("a")) {
            links.add(createJsoupLink(element));
        }
    }
    return links;
}
Also used : Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Elements(org.jsoup.select.Elements)

Example 70 with Element

use of org.jsoup.nodes.Element in project nixmash-blog by mintster.

the class JsoupHtmlParser method twitterContent.

private String twitterContent(String tagName) {
    String selector = String.format("meta[name=twitter:%s]", tagName);
    String content = null;
    Element element = doc.select(selector).first();
    if (element != null) {
        content = element.attr("content");
    }
    return content;
}
Also used : Element(org.jsoup.nodes.Element)

Aggregations

Element (org.jsoup.nodes.Element)1237 Document (org.jsoup.nodes.Document)559 Elements (org.jsoup.select.Elements)529 ArrayList (java.util.ArrayList)316 IOException (java.io.IOException)220 Test (org.junit.Test)144 ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)90 File (java.io.File)87 URL (java.net.URL)82 Matcher (java.util.regex.Matcher)73 List (java.util.List)60 HashMap (java.util.HashMap)57 Pattern (java.util.regex.Pattern)54 Node (org.jsoup.nodes.Node)50 TextNode (org.jsoup.nodes.TextNode)48 InputStream (java.io.InputStream)38 JSONException (org.json.JSONException)36 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)35 Map (java.util.Map)34 JSONObject (org.json.JSONObject)34