Search in sources :

Example 1 with Element

use of org.jsoup.nodes.Element in project jsoup by jhy.

the class ElementsTest method hasClassCaseInsensitive.

@Test
public void hasClassCaseInsensitive() {
    Elements els = Jsoup.parse("<p Class=One>One <p class=Two>Two <p CLASS=THREE>THREE").select("p");
    Element one = els.get(0);
    Element two = els.get(1);
    Element thr = els.get(2);
    assertTrue(one.hasClass("One"));
    assertTrue(one.hasClass("ONE"));
    assertTrue(two.hasClass("TWO"));
    assertTrue(two.hasClass("Two"));
    assertTrue(thr.hasClass("ThreE"));
    assertTrue(thr.hasClass("three"));
}
Also used : Element(org.jsoup.nodes.Element) FormElement(org.jsoup.nodes.FormElement) Test(org.junit.Test)

Example 2 with Element

use of org.jsoup.nodes.Element 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 3 with Element

use of org.jsoup.nodes.Element in project cucumber-jvm by cucumber.

the class HTMLFormatterTest method writes_index_html.

@Test
public void writes_index_html() throws IOException {
    URL indexHtml = new URL(outputDir, "index.html");
    Document document = Jsoup.parse(new File(indexHtml.getFile()), "UTF-8");
    Element reportElement = document.body().getElementsByClass("cucumber-report").first();
    assertEquals("", reportElement.text());
}
Also used : Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 4 with Element

use of org.jsoup.nodes.Element in project Asqatasun by Asqatasun.

the class Rgaa32016Rule060303 method testLink.

/**
     * 
     * @param sspHandler
     * @param el
     * @return 
     */
private TestSolution testLink(SSPHandler sspHandler, Element el) {
    ElementHandler<Element> elHandler = new ElementHandlerImpl(el);
    TestSolutionHandler tsHandler = new TestSolutionHandlerImpl();
    // reset the service for each tested element. We use the collection 
    // handled by the service to feed the local collection of remarks
    prs.resetService();
    // check the pertinence of the link
    getDecidableElementsChecker().check(sspHandler, elHandler, tsHandler);
    // get the processRemark for eventually override it with the result
    // returned by the title pertinence checker
    ProcessRemark remark = prs.getRemarkList().iterator().next();
    // to nmi but the inverse is impossible.
    if (tsHandler.getTestSolution().equals(TestSolution.FAILED)) {
        // check the pertinence of the title of the link
        String linkText = getDecidableElementsChecker().getTextElementBuilder().buildTextFromElement(el);
        if (testTitleAttributeLink(sspHandler, el, linkText).equals(TestSolution.NEED_MORE_INFO)) {
            //override result (evidence element have already been collected
            remark.setIssue(TestSolution.NEED_MORE_INFO);
            remark.setMessageCode(CHECK_LINK_PERTINENCE_MSG);
            remarks.add(remark);
            return TestSolution.NEED_MORE_INFO;
        }
    }
    remarks.add(remark);
    return tsHandler.getTestSolution();
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) TestSolutionHandlerImpl(org.asqatasun.ruleimplementation.TestSolutionHandlerImpl) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler) ProcessRemark(org.asqatasun.entity.audit.ProcessRemark)

Example 5 with Element

use of org.jsoup.nodes.Element in project Asqatasun by Asqatasun.

the class Rgaa32016Rule060303 method testTitleAttributeLink.

/**
     * 
     * @param sspHandler
     * @param el
     * @param linkText
     * @return 
     */
private TestSolution testTitleAttributeLink(SSPHandler sspHandler, Element el, String linkText) {
    // content identical to the link text, returns not applicable.
    if (!el.hasAttr(TITLE_ATTR)) {
        return TestSolution.NOT_APPLICABLE;
    }
    String attrValue = el.attr(TITLE_ATTR);
    if (StringUtils.isBlank(attrValue)) {
        return TestSolution.NOT_APPLICABLE;
    }
    if (StringUtils.equalsIgnoreCase(attrValue, linkText)) {
        return TestSolution.NOT_APPLICABLE;
    }
    ElementHandler<Element> elHandler = new ElementHandlerImpl(el);
    TestSolutionHandler tsHandler = new TestSolutionHandlerImpl();
    titlePertinenceElementChecker.check(sspHandler, elHandler, tsHandler);
    return tsHandler.getTestSolution();
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) TestSolutionHandlerImpl(org.asqatasun.ruleimplementation.TestSolutionHandlerImpl) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler)

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