本文整理汇总了Java中org.jsoup.nodes.Comment类的典型用法代码示例。如果您正苦于以下问题:Java Comment类的具体用法?Java Comment怎么用?Java Comment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Comment类属于org.jsoup.nodes包,在下文中一共展示了Comment类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getChildren
import org.jsoup.nodes.Comment; //导入依赖的package包/类
@Override
public List<HTMLNode> getChildren()
{
if (children != null)
return children;
children = new ArrayList<HTMLNode>();
for (Node node : target.childNodes())
{
HTMLNode htmlNode = null;
if (node instanceof Comment)
{
htmlNode = new HTMLCommentImpl((Comment) node, this);
}
else if (node instanceof Element)
{
htmlNode = new HTMLElementImpl<Element>((Element) node, this);
} else {
htmlNode = new HTMLNodeImpl<Node>( node, this);
}
children.add(htmlNode);
}
return children;
}
示例2: print2
import org.jsoup.nodes.Comment; //导入依赖的package包/类
private void print2(String baseLocation) throws IOException, TransformerException, ParserConfigurationException {
Document document = Jsoup.connect(baseLocation).get();
Elements content = document.getElementsByAttributeValue("class", "entry-content");
String title = null;
ArrayList<String> list = new ArrayList<>();
for (Element div : content) {
List<Node> nodes = div.childNodes();
for (Node node : nodes) {
if (node instanceof Element) {
if (((Element) node).tagName().equals("h3")) {
writeFile(title, list);
list.clear();
System.out.println("Title: " + node.childNode(0));
title = node.childNode(0).toString();
} else if (((Element) node).tagName().equals("table")) {
//print table
Elements tr = ((Element) node).getElementsByTag("tr");
for (Element element : tr) {
Elements td = element.getElementsByTag("td");
for (Element value : td) {
if (value.childNodeSize() > 0) {
if (!(value.childNode(0) instanceof Comment)) {
// System.out.println("Emoticon: " + value.childNode(0) + " " + value.childNode(0).getClass().getSimpleName());
list.add(value.childNode(0).toString());
}
}
}
}
}
}
}
}
}
示例3: matches
import org.jsoup.nodes.Comment; //导入依赖的package包/类
@Override
public boolean matches(Element root, Element element) {
List<Node> family = element.childNodes();
for (Node n : family) {
if (!(n instanceof Comment || n instanceof XmlDeclaration || n instanceof DocumentType)) return false;
}
return true;
}
示例4: matches
import org.jsoup.nodes.Comment; //导入依赖的package包/类
@Override
public boolean matches(Element root, Element element) {
List<Node> family = element.childNodes();
for (int i = 0; i < family.size(); i++) {
Node n = family.get(i);
if (!(n instanceof Comment || n instanceof XmlDeclaration || n instanceof DocumentType)) return false;
}
return true;
}
示例5: parsesComments
import org.jsoup.nodes.Comment; //导入依赖的package包/类
@Test public void parsesComments() {
String html = "<html><head></head><body><img src=foo><!-- <table><tr><td></table> --><p>Hello</p></body></html>";
Document doc = Jsoup.parse(html);
Element body = doc.body();
Comment comment = (Comment) body.childNode(1); // comment should not be sub of img, as it's an empty tag
assertEquals(" <table><tr><td></table> ", comment.getData());
Element p = body.child(1);
TextNode text = (TextNode) p.childNode(0);
assertEquals("Hello", text.getWholeText());
}
示例6: isComment
import org.jsoup.nodes.Comment; //导入依赖的package包/类
@Override
public boolean isComment() {
if (node instanceof Comment) {
return true;
}
return false;
}
示例7: visit
import org.jsoup.nodes.Comment; //导入依赖的package包/类
@Override
public void visit(Node node) {
if (node instanceof TextNode || node instanceof Comment || node instanceof DataNode) {
node.replaceWith(new TextNode(StringUtils.EMPTY, node.baseUri()));
}
}
示例8: insert
import org.jsoup.nodes.Comment; //导入依赖的package包/类
void insert(Token.Comment commentToken) {
Comment comment = new Comment(commentToken.getData());
insertNode(comment);
}
示例9: HTMLCommentImpl
import org.jsoup.nodes.Comment; //导入依赖的package包/类
HTMLCommentImpl(Comment target, HTMLElement parent)
{
super(target, parent);
}