gpt4 book ai didi

org.zkoss.zsoup.Zsoup类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 12:38:48 25 4
gpt4 key购买 nike

本文整理了Java中org.zkoss.zsoup.Zsoup类的一些代码示例,展示了Zsoup类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Zsoup类的具体详情如下:
包路径:org.zkoss.zsoup.Zsoup
类名称:Zsoup

Zsoup介绍

[英]The core public access point to the jsoup functionality.
[中]jsoup功能的核心公共访问点。

代码示例

代码示例来源:origin: org.zkoss/zsoup

/**
 Get safe HTML from untrusted input HTML, by parsing input HTML and filtering it through a white-list of permitted
 tags and attributes.
 @param bodyHtml  input untrusted HTML (body fragment)
 @param whitelist white-list of permitted HTML elements
 @return safe HTML (body fragment)
 @see Cleaner#clean(Document)
 */
public static String clean(String bodyHtml, Whitelist whitelist) {
  return clean(bodyHtml, "", whitelist);
}

代码示例来源:origin: org.zkoss/zsoup

/**
 Test if the input HTML has only tags and attributes allowed by the Whitelist. Useful for form validation. The input HTML should
 still be run through the cleaner to set up enforced attributes, and to tidy the output.
 @param bodyHtml HTML to test
 @param whitelist whitelist to test against
 @return true if no tags or attributes were removed; false otherwise
 @see #clean(String, org.zkoss.zsoup.safety.Whitelist) 
 */
public static boolean isValid(String bodyHtml, Whitelist whitelist) {
  Document dirty = parseBodyFragment(bodyHtml, "");
  Cleaner cleaner = new Cleaner(whitelist);
  return cleaner.isValid(dirty);
}

代码示例来源:origin: org.zkoss.zk/zhtml

public org.zkoss.idom.Document parse(URL url) throws Exception {
  InputStream inStream = null;
  try {
    if (log.isDebugEnabled())
      log.debug("Parsing file: [" + url.toString() + "]");
    inStream = url.openStream();
    return convertToIDOM(
        Zsoup.parse(inStream, "UTF-8", url.getFile(), Parser.xhtmlParser()));
  } catch (UiExceptionX ue) {
    throw ue;
  } catch (ExceptionInfo e) {
    Document currentDocument = e.getCurrentDocument();
    if (currentDocument != null) {
      currentDocument.outputSettings(currentDocument.outputSettings().prettyPrint(false));
      throw new UiException(" at [file:" + url.getFile() + ", "
          + getLineNumber(new Scanner(currentDocument.toString())) + "]", e);
    } else
      throw new UiException(" at [file:" + url.getFile() + "]", e);
  } finally {
    if (inStream != null)
      inStream.close();
  }
}

代码示例来源:origin: org.zkoss/zsoup

public static void main(String... args) throws IOException {
  Validate.isTrue(args.length == 1, "usage: supply url to fetch");
  String url = args[0];
  // fetch the specified URL and parse to a HTML DOM
  Document doc = Zsoup.connect(url).get();
  HtmlToPlainText formatter = new HtmlToPlainText();
  String plainText = formatter.getPlainText(doc);
  System.out.println(plainText);
}

代码示例来源:origin: org.zkoss.zk/zhtml

public org.zkoss.idom.Document parse(Reader reader) throws Exception {
  ReaderInputStream inputStream = null;
  try {
    if (log.isDebugEnabled())
      log.debug("Parsing reader: [" + reader + "]");
    inputStream = new ReaderInputStream(reader);
    return convertToIDOM(Zsoup.parse(inputStream, "UTF-8", null, Parser.xhtmlParser()));
  } catch (UiExceptionX ue) {
    String lineNumber = getLineNumber(reader, ue.getKeyword());
    if (lineNumber != null)
      throw new UiException(ue.getMessage() + lineNumber);
    else
      throw ue;
  } finally {
    if (inputStream != null)
      inputStream.close();
  }
}

代码示例来源:origin: org.zkoss/zsoup

/**
 * Prepare to submit this form. A Connection object is created with the request set up from the form values. You
 * can then set up other options (like user-agent, timeout, cookies), then execute it.
 * @return a connection prepared from the values of this form.
 * @throws IllegalArgumentException if the form's absolute action URL cannot be determined. Make sure you pass the
 * document's base URI when parsing.
 */
public Connection submit() {
  String action = hasAttr("action") ? absUrl("action") : baseUri();
  Validate.notEmpty(action, "Could not determine a form action URL for submit. Ensure you set a base URI when parsing.");
  Connection.Method method = attr("method").toUpperCase().equals("POST") ?
      Connection.Method.POST : Connection.Method.GET;
  Connection con = Zsoup.connect(action)
      .data(formData())
      .method(method);
  return con;
}

代码示例来源:origin: org.zkoss.zats/zats-mimic

Document doc = Zsoup.parse(new ByteArrayInputStream(raw.getBytes("utf-8")), "UTF-8",
    "", org.zkoss.zsoup.parser.Parser.xhtmlParser());
Elements scripts = doc.getElementsByTag("script");

代码示例来源:origin: org.zkoss/zsoup

public static void main(String[] args) throws IOException {
  Validate.isTrue(args.length == 1, "usage: supply url to fetch");
  String url = args[0];
  print("Fetching %s...", url);
  Document doc = Zsoup.connect(url).get();
  Elements links = doc.select("a[href]");
  Elements media = doc.select("[src]");
  Elements imports = doc.select("link[href]");
  print("\nMedia: (%d)", media.size());
  for (Element src : media) {
    if (src.tagName().equals("img"))
      print(" * %s: <%s> %sx%s (%s)",
          src.tagName(), src.attr("abs:src"), src.attr("width"), src.attr("height"),
          trim(src.attr("alt"), 20));
    else
      print(" * %s: <%s>", src.tagName(), src.attr("abs:src"));
  }
  print("\nImports: (%d)", imports.size());
  for (Element link : imports) {
    print(" * %s <%s> (%s)", link.tagName(),link.attr("abs:href"), link.attr("rel"));
  }
  print("\nLinks: (%d)", links.size());
  for (Element link : links) {
    print(" * a: <%s>  (%s)", link.attr("abs:href"), trim(link.text(), 35));
  }
}

代码示例来源:origin: org.zkoss/zsoup

/**
 Get safe HTML from untrusted input HTML, by parsing input HTML and filtering it through a white-list of permitted
 tags and attributes.
 @param bodyHtml  input untrusted HTML (body fragment)
 @param baseUri   URL to resolve relative URLs against
 @param whitelist white-list of permitted HTML elements
 @return safe HTML (body fragment)
 @see Cleaner#clean(Document)
 */
public static String clean(String bodyHtml, String baseUri, Whitelist whitelist) {
  Document dirty = parseBodyFragment(bodyHtml, baseUri);
  Cleaner cleaner = new Cleaner(whitelist);
  Document clean = cleaner.clean(dirty);
  return clean.body().html();
}

代码示例来源:origin: org.zkoss/zsoup

/**
 * Get safe HTML from untrusted input HTML, by parsing input HTML and filtering it through a white-list of
 * permitted
 * tags and attributes.
 *
 * @param bodyHtml input untrusted HTML (body fragment)
 * @param baseUri URL to resolve relative URLs against
 * @param whitelist white-list of permitted HTML elements
 * @param outputSettings document output settings; use to control pretty-printing and entity escape modes
 * @return safe HTML (body fragment)
 * @see Cleaner#clean(Document)
 */
public static String clean(String bodyHtml, String baseUri, Whitelist whitelist, Document.OutputSettings outputSettings) {
  Document dirty = parseBodyFragment(bodyHtml, baseUri);
  Cleaner cleaner = new Cleaner(whitelist);
  Document clean = cleaner.clean(dirty);
  clean.outputSettings(outputSettings);
  return clean.body().html();
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com