当前位置: 首页>>代码示例>>Java>>正文


Java Attributes类代码示例

本文整理汇总了Java中net.htmlparser.jericho.Attributes的典型用法代码示例。如果您正苦于以下问题:Java Attributes类的具体用法?Java Attributes怎么用?Java Attributes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Attributes类属于net.htmlparser.jericho包,在下文中一共展示了Attributes类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: replaceUrlAttribute

import net.htmlparser.jericho.Attributes; //导入依赖的package包/类
protected int replaceUrlAttribute ( Iterable<StartTag> tags, final String pathAttribute, PathOrigin baseDir, OutputDocument doc ) {
  int count = 0;
  for ( StartTag tag : tags ) {
    Attributes attr = tag.parseAttributes();
    String path = attr.getValue( pathAttribute );
    if ( shouldProcessPath( path ) ) {
      String newPath = processPath( baseDir, path, getUrlProvider() );
      if ( log.isTraceEnabled() ) { //TODO: trace
        log.trace( String.format( "replaced: in %[email protected]%s \"%s\" --> \"%s\"", tag.getName(), pathAttribute, path, newPath ) );
      }
      doc.replace( attr, true ).put( pathAttribute, newPath );
      count++;
    }
  }
  return count;
}
 
开发者ID:webdetails,项目名称:cte,代码行数:17,代码来源:ProcessedHtmlPage.java

示例2: removeNotAllowedTags

import net.htmlparser.jericho.Attributes; //导入依赖的package包/类
/**
    * Serduszko dla Bartka od Kasi <3
    * @param htmlFragment
    * @param docUri
    * @return
    */
   private String removeNotAllowedTags(String htmlFragment, URI docUri) {
       Source source = new Source(htmlFragment);
       OutputDocument outputDocument = new OutputDocument(source);
       List<Element> elements = source.getAllElements();


    for (Element element : elements) {
    	Attributes attrs = element.getAttributes();
    	Map<String, String> attrsUpdate = outputDocument.replace(attrs, true);
    	if (!element.getName().contains("a")) {
			attrsUpdate.clear();
		} else {
    		if (attrsUpdate.get("href")!=null) {
	    		String link = attrsUpdate.get("href");
	    		if (!link.contains("http")) {
		    		URI documentUri = docUri;

		    		URI anchorUri;
					try {
						anchorUri = new URI(link);
						URI result = documentUri.resolve(anchorUri);

						attrsUpdate.put("href",	result.toString());
					} catch (URISyntaxException e) {
						outputDocument.remove(element);
					}
	    		}
    		}
    	}

    	if (NOT_ALLOWED_HTML_TAGS.contains(element.getName())) {
    		Segment content = element.getContent();
    		if (element.getName() == "script"
    				|| element.getName() == "style"
    				|| element.getName() == "form") {
    			outputDocument.remove(content);
    		}
            outputDocument.remove(element.getStartTag());

            if (!element.getStartTag().isSyntacticalEmptyElementTag()) {
                outputDocument.remove(element.getEndTag());
            }
        }
    }

    String out = outputDocument.toString();
    out = out.replaceAll("\\n", "");
    out = out.replaceAll("\\t", "");

    return out;
}
 
开发者ID:BartoszJarocki,项目名称:android-boilerpipe,代码行数:58,代码来源:HtmlArticleExtractor.java


注:本文中的net.htmlparser.jericho.Attributes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。