Search in sources :

Example 71 with Element

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

the class JsoupHtmlParser method parseSelector.

private String parseSelector(Field f) {
    String selector = f.getAnnotation(Selector.class).value();
    Elements elems = doc.select(selector);
    if (elems.size() > 0) {
        final Element elem = elems.get(0);
        // Check which value annotation is present and retrieve data depending on the type of annotation
        if (f.isAnnotationPresent(TextValue.class)) {
            return elem.text();
        } else if (f.isAnnotationPresent(HtmlValue.class)) {
            return elem.html();
        } else if (f.isAnnotationPresent(AttributeValue.class)) {
            return elem.attr(f.getAnnotation(AttributeValue.class).name());
        } else
            return elem.text();
    }
    return null;
}
Also used : Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements)

Example 72 with Element

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

the class JsoupHtmlParser method parseLink.

private JsoupLink parseLink(Field f) {
    String css = f.getAnnotation(LinkSelector.class).value();
    String selector = String.format("a[href]%s", css);
    Element element = doc.select(selector).first();
    if (element != null) {
        return createJsoupLink(element);
    }
    return null;
}
Also used : Element(org.jsoup.nodes.Element)

Example 73 with Element

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

the class JsoupHtmlParser method parseImage.

private JsoupImage parseImage(Field f) {
    String css = f.getAnnotation(ImageSelector.class).value();
    String selector = String.format("img%s", css);
    Element media = doc.select(selector).first();
    if (media != null) {
        return createImageElement(media);
    }
    return null;
}
Also used : Element(org.jsoup.nodes.Element)

Example 74 with Element

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

the class JsoupHtmlParser method parseMetaProperty.

private String parseMetaProperty(Field f) {
    String tagproperty = f.getAnnotation(MetaProperty.class).value();
    String selector = String.format("meta[property=%s]", tagproperty);
    Element element = doc.select(selector).first();
    if (element != null)
        return element.attr("content");
    return null;
}
Also used : Element(org.jsoup.nodes.Element)

Example 75 with Element

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

the class JsoupHtmlParser method parseMetaName.

private String parseMetaName(Field f) {
    String tagname = f.getAnnotation(MetaName.class).value();
    String selector = String.format("meta[name=%s]", tagname);
    Element element = doc.select(selector).first();
    if (element != null)
        return element.attr("content");
    return null;
}
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