Search in sources :

Example 1 with Elements

use of org.jsoup.select.Elements in project ZhihuDailyPurify by izzyleung.

the class NewsListFromZhihuObservable method getQuestions.

private static List<Question> getQuestions(Document document, String dailyTitle) {
    List<Question> result = new ArrayList<>();
    Elements questionElements = getQuestionElements(document);
    for (Element questionElement : questionElements) {
        Question question = new Question();
        String questionTitle = getQuestionTitleFromQuestionElement(questionElement);
        String questionUrl = getQuestionUrlFromQuestionElement(questionElement);
        // Make sure that the question's title is not empty.
        questionTitle = TextUtils.isEmpty(questionTitle) ? dailyTitle : questionTitle;
        question.setTitle(questionTitle);
        question.setUrl(questionUrl);
        result.add(question);
    }
    return result;
}
Also used : Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Question(io.github.izzyleung.zhihudailypurify.bean.Question) Elements(org.jsoup.select.Elements)

Example 2 with Elements

use of org.jsoup.select.Elements in project opennms by OpenNMS.

the class HttpCollectionHandler method fillCollectionSet.

@Override
protected void fillCollectionSet(String urlString, Request request, CollectionAgent agent, CollectionSetBuilder builder, XmlSource source) throws Exception {
    Document doc = getJsoupDocument(urlString, request);
    for (XmlGroup group : source.getXmlGroups()) {
        LOG.debug("fillCollectionSet: getting resources for XML group {} using selector {}", group.getName(), group.getResourceXpath());
        Date timestamp = getTimeStamp(doc, group);
        Elements elements = doc.select(group.getResourceXpath());
        LOG.debug("fillCollectionSet: {} => {}", group.getResourceXpath(), elements);
        String resourceName = getResourceName(elements, group);
        LOG.debug("fillCollectionSet: processing XML resource {}", resourceName);
        final Resource collectionResource = getCollectionResource(agent, resourceName, group.getResourceType(), timestamp);
        LOG.debug("fillCollectionSet: processing resource {}", collectionResource);
        for (XmlObject object : group.getXmlObjects()) {
            Elements el = elements.select(object.getXpath());
            if (el == null) {
                LOG.info("No value found for object named '{}'. Skipping.", object.getName());
            }
            builder.withAttribute(collectionResource, group.getName(), object.getName(), el.html(), object.getDataType());
        }
        processXmlResource(builder, collectionResource, resourceName, group.getName());
    }
}
Also used : XmlGroup(org.opennms.protocols.xml.config.XmlGroup) Resource(org.opennms.netmgt.collection.support.builder.Resource) XmlObject(org.opennms.protocols.xml.config.XmlObject) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Date(java.util.Date)

Example 3 with Elements

use of org.jsoup.select.Elements in project Asqatasun by Asqatasun.

the class Rgaa32016Rule110102 method putLabelElementHandlerIntoTheMap.

/**
     * This method linked each label which have an input child on a page to its
     * form in a map.
     */
private void putLabelElementHandlerIntoTheMap() {
    for (Element el : labelElementHandler.get()) {
        Element tmpElement = el.parent();
        while (tmpElement != null && StringUtils.isNotBlank(tmpElement.tagName())) {
            if (tmpElement.tagName().equals(FORM_ELEMENT)) {
                if (labelFormMap.containsKey(tmpElement)) {
                    Elements els = el.select(FORM_ELEMENT_WITH_ID_CSS_LIKE_QUERY);
                    if (!els.isEmpty()) {
                        labelFormMap.get(tmpElement).add(el);
                    }
                } else {
                    Elements els = el.select(FORM_ELEMENT_WITH_ID_CSS_LIKE_QUERY);
                    if (!els.isEmpty()) {
                        ElementHandler<Element> labelElement = new ElementHandlerImpl();
                        labelElement.add(el);
                        labelFormMap.put(tmpElement, labelElement);
                    }
                }
                break;
            }
            tmpElement = tmpElement.parent();
        }
    }
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) Elements(org.jsoup.select.Elements)

Example 4 with Elements

use of org.jsoup.select.Elements in project Asqatasun by Asqatasun.

the class Rgaa32016Rule050201 method select.

@Override
protected void select(SSPHandler sspHandler) {
    super.select(sspHandler);
    // once tables selected, we extract the caption child element of each 
    // to make the control
    Elements captionOnTable = new Elements();
    for (Element el : getSelectionWithoutMarkerHandler().get()) {
        captionOnTable.add(el.select(CAPTION_ELEMENT).first());
    }
    getSelectionWithoutMarkerHandler().clean().addAll(captionOnTable);
    Elements captionOnDataTable = new Elements();
    for (Element el : getSelectionWithMarkerHandler().get()) {
        captionOnDataTable.add(el.select(CAPTION_ELEMENT).first());
    }
    getSelectionWithMarkerHandler().clean().addAll(captionOnDataTable);
}
Also used : Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements)

Example 5 with Elements

use of org.jsoup.select.Elements in project AndroidDevelop by 7449.

the class JsoupTool method getDetail.

public DetailModel getDetail(String url) {
    Document document = getDocument(url);
    DetailModel detailModel = new DetailModel();
    if (document == null) {
        throw new NullPointerException("the document is null");
    }
    Elements select = document.select("div.bottem2").select("a[href$=.html]");
    for (int i = 0; i < select.size(); i++) {
        switch(i) {
            case 0:
                detailModel.setOnPage(select.get(i).attr("abs:href"));
                break;
            case 1:
                detailModel.setNextPage(select.get(i).attr("abs:href"));
                break;
        }
    }
    detailModel.setTitle(document.select("div.bookname").select("h1").text());
    detailModel.setContent(document.select("#content").html());
    KLog.i(detailModel.getOnPage() + "    " + detailModel.getNextPage());
    return detailModel;
}
Also used : DetailModel(com.fiction.y.detail.m.DetailModel) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Aggregations

Elements (org.jsoup.select.Elements)774 Element (org.jsoup.nodes.Element)500 Document (org.jsoup.nodes.Document)383 ArrayList (java.util.ArrayList)216 IOException (java.io.IOException)153 Test (org.junit.Test)94 Test (org.junit.jupiter.api.Test)68 URL (java.net.URL)58 List (java.util.List)48 Matcher (java.util.regex.Matcher)42 Pattern (java.util.regex.Pattern)34 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)31 HashMap (java.util.HashMap)30 File (java.io.File)29 InputStream (java.io.InputStream)29 Jsoup (org.jsoup.Jsoup)29 Configuration (com.vaadin.addon.charts.model.Configuration)27 JSONObject (org.json.JSONObject)26 Collectors (java.util.stream.Collectors)25 JSONException (org.json.JSONException)25