本文整理汇总了Java中us.codecraft.xsoup.Xsoup.convertDocument方法的典型用法代码示例。如果您正苦于以下问题:Java Xsoup.convertDocument方法的具体用法?Java Xsoup.convertDocument怎么用?Java Xsoup.convertDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类us.codecraft.xsoup.Xsoup
的用法示例。
在下文中一共展示了Xsoup.convertDocument方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testByAttribute
import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testByAttribute() throws XPathExpressionException {
org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(html));
assertThat(getNodeValue(document, "//a[@href]")).isEqualTo("<a href=\"https://github.com\">github.com</a>");
assertThat(getNodeValue(document, "//a[@id]")).isNull();
String expectedDiv = "<div id=\"test\">\n" +
" aaa\n" +
" <div>\n" +
" <a href=\"https://github.com\">github.com</a>\n" +
" </div>\n" +
"</div>";
//TODO: illegal
//assertThat(getNodeValue(document,"//div[@id=test]")).isEqualTo(expectedDiv);
assertThat(getNodeValue(document, "//div[@id='test']")).isEqualTo(expectedDiv);
assertThat(getNodeValue(document, "//div[@id=\"test\"]")).isEqualTo(expectedDiv);
}
示例2: testNth
import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testNth() throws XPathExpressionException {
org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(htmlClass));
assertThat(getNodeValue(document, "//body/div[1]")).isEqualTo("<div class=\"a b c\">\n" +
" <div>\n" +
" <a href=\"https://github.com\">github.com</a>\n" +
" </div>\n" +
"</div>");
assertThat(getNodeValue(document, "//body/div[2]")).isEqualTo("<div>\n" +
" b\n" +
"</div>");
String htmlSVG = "<div><svg>1</svg><svg>2</svg></div>";
document = Xsoup.convertDocument(Jsoup.parse(htmlSVG));
assertThat(getNodeValue(document, "//div/svg[1]")).isEqualTo("<svg>\n" +
" 1\n" +
"</svg>");
assertThat(getNodeValue(document, "//div/svg[2]")).isEqualTo("<svg>\n" +
" 2\n" +
"</svg>");
}
示例3: testSelect
import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testSelect() throws XPathExpressionException {
String html = "<html><div><a href='https://github.com'>github.com</a></div>" +
"<table><tr><td>a</td><td>b</td></tr></table></html>";
org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(html));
assertThat(getStringValue(document, "//div/a/@href")).isEqualTo("https://github.com");
List<String> nodeListValue = getNodeListValue(document, "//tr/td");
assertThat(nodeListValue.get(0)).isEqualTo("<td>a</td>");
assertThat(nodeListValue.get(1)).isEqualTo("<td>b</td>");
}
示例4: testContains
import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testContains() throws XPathExpressionException {
org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(html));
assertThat(getNodeValue(document,"//div[contains(@id,'te')]")).isEqualTo("<div id=\"test\">\n" +
" aaa\n" +
" <div>\n" +
" <a href=\"https://github.com\">github.com</a>\n" +
" </div>\n" +
"</div>");
}
示例5: testClass
import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testClass() throws XPathExpressionException {
org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(htmlClass));
assertThat(getNodeListValue(document,"//div[@class='a b c']").get(0)).isEqualTo("<div class=\"a b c\">\n" +
" <div>\n" +
" <a href=\"https://github.com\">github.com</a>\n" +
" </div>\n" +
"</div>");
assertThat(getNodeListValue(document, "//div[@class='b']")).isNullOrEmpty();
assertThat(getNodeListValue(document, "//div[@class='d']")).isNullOrEmpty();
}
示例6: testAttribute
import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testAttribute() throws XPathExpressionException {
org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(htmlClass));
assertThat(getStringValue(document,"//a/@href")).isEqualTo("https://github.com");
//TODO: not support
//assertThat(getStringValue(document,"//a/text()")).isEqualTo("github.com");
//TODO: not support
//assertThat(getStringValue(document,"//div[@class=a]/html()")).isEqualTo("<div>\n" +
// " <a href=\"https://github.com\">github.com</a>\n" +
// "</div>");
}
示例7: testLogicOperation
import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testLogicOperation() throws XPathExpressionException {
org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(html));
String expectedDiv = "<div id=\"test\">\n" +
" aaa\n" +
" <div>\n" +
" <a href=\"https://github.com\">github.com</a>\n" +
" </div>\n" +
"</div>";
assertThat(getNodeValue(document, "//*[@id='te' or @id='test']")).isEqualTo(expectedDiv);
assertThat(getNodeValue(document, "//*[@id='te' and @id='test']")).isNullOrEmpty();
assertThat(getNodeValue(document, "//*[@id='te' and @id='test']")).isNullOrEmpty();
assertThat(getNodeValue(document,"//*[(@id='te' or @id='test') and @id='test']")).isEqualTo(expectedDiv);
assertThat(getNodeValue(document,"//*[@id='te' or (@id='test' and @id='id')]")).isNull();
}
示例8: testParent
import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testParent() throws XPathExpressionException {
org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(html));
assertThat(getNodeValue(document, "/html/body/div/div/a")).isEqualTo("<a href=\"https://github.com\">github.com</a>");
assertThat(getNodeValue(document, "/html//div/div/a")).isEqualTo("<a href=\"https://github.com\">github.com</a>");
assertThat(getNodeValue(document, "/html/div/div/a")).isNull();
}
示例9: testCombingXPath
import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testCombingXPath() throws XPathExpressionException {
String html2 = "<html><div id='test2'>aa<a href='https://github.com'>github.com</a></div>";
String expectedDiv1 = "<div id=\"test\">\n" +
" aaa\n" +
" <div>\n" +
" <a href=\"https://github.com\">github.com</a>\n" +
" </div>\n" +
"</div>";
String expectedDiv2 = "<div id=\"test2\">\n" +
" aa\n" +
" <a href=\"https://github.com\">github.com</a>\n" +
"</div>";
org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(html));
assertThat(getNodeValue(document, "//div[@id='test'] | //div[@id='test2']")).isEqualTo(expectedDiv1);
document = Xsoup.convertDocument(Jsoup.parse(html2));
assertThat(getNodeValue(document, "//div[@id='test'] | //div[@id='test2']")).isEqualTo(expectedDiv2);
document = Xsoup.convertDocument(Jsoup.parse(html+html2));
assertThat(getNodeListValue(document, "//div[@id='test'] | //div[@id='test2']")).contains(expectedDiv1,expectedDiv2);
}