Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何查找不在<;a>;使用HtmlCleaner标记?_Java_Data Mining_Htmlcleaner - Fatal编程技术网

Java 如何查找不在<;a>;使用HtmlCleaner标记?

Java 如何查找不在<;a>;使用HtmlCleaner标记?,java,data-mining,htmlcleaner,Java,Data Mining,Htmlcleaner,我使用HTMLCleaner来挖掘数据。。。。 以下是它的工作原理: HtmlCleaner cleaner = new HtmlCleaner(); final String siteUrl = "http://www.apple.com/"; TagNode node = cleaner.clean(new URL(siteUrl)); TagNode[] aTagNode = node.getAllElements(true); for(int

我使用HTMLCleaner来挖掘数据。。。。 以下是它的工作原理:

    HtmlCleaner cleaner = new HtmlCleaner();
    final String siteUrl = "http://www.apple.com/";

    TagNode node = cleaner.clean(new URL(siteUrl));
    TagNode[] aTagNode = node.getAllElements(true);

    for(int i = 0; i< aTagNode.length; i++){
            if(!aTagNode[i].hasAttribute("a")){
                System.out.println(aTagNode[i].getText());
            }
    }
HtmlCleaner cleaner=新的HtmlCleaner();
最终字符串siteUrl=”http://www.apple.com/";
TagNode节点=cleaner.clean(新URL(siteUrl));
TagNode[]aTagNode=node.getAllegements(true);
for(int i=0;i
但我发现有些问题。。。。 例如,获取文本:

                <a href="/choose-your-country/"> 
                    <img src="http://images.apple.com/home/elements/worldwide_us.png" alt="United States of America" height="22" width="22" /> 
                    <span class="more">Choose your country or region</span> 
                </a> 

“选择您的国家或地区”位于span标记内,但其父节点是“a”标记。。。。。我也不想要,我只想要这样的东西

<p class="left">Shop the <a href="/store/">Apple Online Store</a> (1-800-MY-APPLE), visit an <a href="/retail/">Apple Retail Store</a>, or find a <a href="/buy/">reseller</a>.</p> 

购买(1-800-MY-APPLE)、访问或查找。

我希望结果是
停止
(1-800-MY-APPLE),访问
或查找
,以及
因为
苹果在线商店
苹果零售商店
经销商
是a标签中的文本,所以我想忽略这些词。多谢各位

TagNode[]aTagNode=node.getAllegements(true);
    TagNode[] aTagNode = node.getAllElements(true);
    ArrayList<TagNode> tagNodes = new ArrayList<TagNode>();
    Set<TagNode> toBeRemoved = new HashSet<TagNode>();
    for(int i = 0; i< aTagNode.length; i++){
            if(!aTagNode[i].hasAttribute("a")){
                tagNodes.add(aTagNode[i]);
            }else{
                TagNode[] children = aTagNode[i].getChildTags().
                for(TagNode child : children) {
                toBeRemoved.add(child);
                }
             }
    }
    for(TagNode node : tagNodes){
      if(!toBeRemoved.contains(node)){
        System.out.println(node.getText());
      }
    }
ArrayList标记节点=新的ArrayList(); Set toBeRemoved=新HashSet(); for(int i=0;i