English 中文(简体)
Jsoup für Grained Parse
原标题:Jsoup Fine Grained Parse

我正试图通过一个网页上的每一门帽子,看看它是否有文本。 如果是的话,我想在案文中删除:

  Document doc = Jsoup.connect(site).get();     
    Elements e = doc.body().getAllElements();
      for (int i=0; i<e.size(); i++){
         if(doc.body().child(i).hasText()){
        System.out.println(doc.body().child(i).text());
          }
       }

最重要的是,但我不希望这样做。 看来,由于这种方法将多个小类元素加在一起,因此并没有对孩子进行罚款。 我怎么能够以更细微的方式向OMS机构提一下,看每个政党的案文是什么?

事先感谢你。

最佳回答
    Document doc = Jsoup.connect(site).get();
    doc.body().traverse(new NodeVisitor() {

        @Override
        public void head(Node node, int depth) {
            if (node instanceof TextNode) {
                TextNode tn = ((TextNode) node);
                // Try to improve this filter for the nodes who contain
                // texts with a whitespaces
                if (tn.text().replaceAll("\s*", "").length() > 0) {
                    System.out.println("Tag:" + tn.parent().nodeName()
                            + ", text:" + tn.text());
                }
            }
        }

        @Override
        public void tail(Node node, int depth) {
            // Do Nothing
        }
    });
问题回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签