org.jsoup.parser.Tag类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(122)

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

Tag介绍

[英]HTML Tag capabilities.
[中]HTML标签功能。

代码示例

代码示例来源:origin: jooby-project/jooby

@Override
public void run(final Config conf) throws Exception {
 String input = get("input");
 if (input == null) {
  throw new IllegalArgumentException("Required option 'svg-symbol.input' not present");
 }
 Path basedir = Paths.get(get("basedir").toString());
 Path dir = basedir.resolve(input);
 List<CharSequence> cssout = new ArrayList<>();
 Element svg = new Element(Tag.valueOf("svg"), "");
 attrs("svg", "output").forEach((n, v) -> svg.attr(n, v.toString()));
 files(dir, file -> {
  log.debug("{}", file);
  String id = get("id.prefix") + file.getFileName().toString().replace(".svg", "")
    + get("id.suffix");
  Tuple<Element, Element> rewrite = symbol(file, id);
  svg.appendChild(rewrite._2);
  cssout.add(css(id, rewrite._1));
 });
 write(basedir.resolve(svgPath()), ImmutableList.of(svg.outerHtml()));
 write(basedir.resolve(cssPath()), cssout);
}

代码示例来源:origin: org.jsoup/jsoup

/**
 * Get the name of the tag for this element. E.g. {@code div}
 * 
 * @return the tag name
 */
public String tagName() {
  return tag.getName();
}

代码示例来源:origin: org.jsoup/jsoup

protected int calculatePosition(Element root, Element element) {
  int pos = 0;
  Elements family = element.parent().children();
  for (Element el : family) {
    if (el.tag().equals(element.tag())) pos++;
    if (el == element) break;
  }
  return pos;
}

代码示例来源:origin: org.jsoup/jsoup

Element insertEmpty(Token.StartTag startTag) {
  Tag tag = Tag.valueOf(startTag.name(), settings);
  Element el = new Element(tag, baseUri, startTag.attributes);
  insertNode(el);
  if (startTag.isSelfClosing()) {
    if (tag.isKnownTag()) {
      if (!tag.isEmpty())
        tokeniser.error("Tag cannot be self closing; not a void tag");
    }
    else // unknown tag, remember this is self closing for output
      tag.setSelfClosing();
  }
  return el;
}

代码示例来源:origin: org.jsoup/jsoup

void outerHtmlHead(final Appendable accum, int depth, final Document.OutputSettings out) throws IOException {
  if (out.prettyPrint() && (tag.formatAsBlock() || (parent() != null && parent().tag().formatAsBlock()) || out.outline())) {
    if (accum instanceof StringBuilder) {
      if (((StringBuilder) accum).length() > 0)
        indent(accum, depth, out);
    } else {
      indent(accum, depth, out);
    }
  }
  accum.append('<').append(tagName());
  if (attributes != null) attributes.html(accum, out);
  // selfclosing includes unknown tags, isEmpty defines tags that are always empty
  if (childNodes.isEmpty() && tag.isSelfClosing()) {
    if (out.syntax() == Document.OutputSettings.Syntax.html && tag.isEmpty())
      accum.append('>');
    else
      accum.append(" />"); // <img> in html, <img /> in xml
  }
  else
    accum.append('>');
}

代码示例来源:origin: perfectsense/brightspot-cms

if (next != null && BR_TAG.equals(next.tag())) {
    next.remove();
body.select(".cms-textAlign-left, .cms-textAlign-center, .cms-textAlign-right")
    .forEach(div -> div.tagName(tag.getName()));
for (Element br : body.getElementsByTag(BR_TAG.getName())) {
  Element previousBr = null;
      if (BR_TAG.equals(previousElement.tag())) {
        previousBr = previousElement;
  Element paragraph = body.ownerDocument().createElement(tag.getName());
for (Element div : body.getElementsByTag(DIV_TAG.getName())) {
  Element brDiv = nextTag(DIV_TAG, div);
        && BR_TAG.equals(((Element) child).tag())) {
  div.tagName(tag.getName());
  brDiv.remove();
    div.tagName(tag.getName());
for (Element paragraph : body.getElementsByTag(tag.getName())) {
  if (paragraph.getElementsByTag(tag.getName()).size() > 1) {
    paragraph.unwrap();
  if (tag.equals(paragraph.tag())) {

代码示例来源:origin: opacapp/opacclient

String error = doc.select(".error").first().text().trim();
  if (error.equals("Es wurde nichts gefunden.")
      || error.equals("Nothing has been found")
String resultnumstr = doc.select(".pages").first().text();
Pattern p = Pattern.compile("[0-9]+$");
Matcher m = p.matcher(resultnumstr);
for (int i = 0; i < links.size(); i++) {
  Element node = links.get(i);
  if (node.hasAttr("href") & node.attr("href").contains("SHW?")
      && !haslink) {
    haslink = true;
          if (text.length() > 3) {
            strings.add(new String[]{
                ((Element) node).tag().getName(),
                "text", text,
                ((Element) node).className(),
          if (text.length() > 3) {
            strings.add(new String[]{
                ((Element) node).tag().getName(),
                ((Element) subnode).tag().getName(),
                text, ((Element) node).className(),
                node.attr("style")});

代码示例来源:origin: UKPLab/argument-reasoning-comprehension-task

for (Node child : pElement.childNodes()) {
  if (child instanceof TextNode) {
    TextNode textNode = (TextNode) child;
    if ("br".equals(element.tag().getName())) {
      sb.append("\n");
    else if ("a".equals(element.tag().getName())) {
      sb.append(" ").append(element.attr("href")).append(" ");

代码示例来源:origin: opacapp/opacclient

for (int i = 0; i < detailtrs1.size(); i++) {
  Element tr = detailtrs1.get(i);
  int s = tr.children().size();
  if (tr.child(0).text().trim().equals("Titel") && !title_is_set) {
    result.setTitle(tr.child(s - 1).text().trim());
    title_is_set = true;
    try {
      if (node instanceof Element) {
        if (((Element) node).tag().getName().equals("br")) {
          copy.setBranch(pop);
          result.addCopy(copy);
          j = -1;
        } else if (((Element) node).tag().getName().equals("b")
            && j == 1) {
          copy.setLocation(((Element) node).text());
        } else if (((Element) node).tag().getName().equals("b")
            && j > 1) {
          copy.setStatus(((Element) node).text());

代码示例来源:origin: com.vaadin/flow-server

private static Element createHtmlImportElement(String url) {
  final Element htmlImportElement;
  if (url != null) {
    htmlImportElement = new Element(Tag.valueOf("link"), "")
        .attr("rel", "import").attr("href", url);
  } else {
    htmlImportElement = new Element(Tag.valueOf("span"), "")
        .attr("hidden", true);
  }
  return htmlImportElement;
}

代码示例来源:origin: org.tinymediamanager.plugins/scraper-imdb

String movieTitle = cleanString(title.attr("content"));
 int yearStart = movieTitle.lastIndexOf("(");
 if (yearStart > 0) {
 String content = originalTitleYear.attr("content");
 int startOfYear = content.lastIndexOf("(");
 if (startOfYear > 0) {
 String posterUrl = poster.attr("content");
for (Element element : elements) {
 if (!"td".equals(element.tag().getName())) {
  continue;
while (directorsElement != null && directorsElement.tag().getName() != "header") {
 directorsElement = directorsElement.parent();
while (writersElement != null && writersElement.tag().getName() != "header") {
 writersElement = writersElement.parent();
while (producersElement != null && producersElement.tag().getName() != "header") {
 producersElement = producersElement.parent();
while (prodCompHeaderElement != null && prodCompHeaderElement.tag().getName() != "header") {
 prodCompHeaderElement = prodCompHeaderElement.parent();

代码示例来源:origin: org.jsoup/jsoup

for (int i = stack.size() - 1; i > 0; i--) {
  Element el = stack.get(i);
  if (el.nodeName().equals("li")) {
    tb.processEndTag("li");
    break;
  if (tb.isSpecial(el) && !StringUtil.inSorted(el.nodeName(), Constants.InBodyStartLiBreakers))
    break;
  if (!html.hasAttr(attribute.getKey()))
    html.attributes().put(attribute);
      break;
    Element replacement = new Element(Tag.valueOf(node.nodeName(), ParseSettings.preserveCase), tb.getBaseUri());

代码示例来源:origin: persado/stevia

if (e.tagName().contains("root")) continue; //skip the html element!
if (e.tag().isFormSubmittable() || e.tag().getName().equals("a") || e.tag().getName().equals("button")) {
  if ( e.tag().isFormSubmittable() ) {
    String loc = e.nodeName();
    if (e.parent() != null) {

代码示例来源:origin: com.soulgalore/crawler

private Set<PageURL> fetch(String query, String attributeKey, Document doc, String url) {

  final Set<PageURL> urls = new HashSet<PageURL>();

  final Elements elements = doc.select(query);

  for (Element src : elements) {

   if (src.attr(attributeKey).isEmpty()) continue;

   // don't fetch mailto links
   if (src.attr(attributeKey).startsWith(MAIL_TO))
    continue;

   else if (IFRAME.equals(src.tag().getName()))
    urls.add(new PageURL(src.attr(attributeKey), url));

   else
    urls.add(new PageURL(src.attr(attributeKey), url));

  }

  return urls;

 }
}

代码示例来源:origin: jooby-project/jooby

/**
 * Read a svg file and return the svg element (original) and a new symbol element (created from
 * original).
 *
 * @param file Svg file.
 * @param id   ID to use.
 * @return Svg element (original) and a symbol element (converted).
 * @throws IOException If something goes wrong.
 */
private Tuple<Element, Element> symbol(final Path file, final String id) throws IOException {
 Element svg = Jsoup.parse(file.toFile(), "UTF-8").select("svg").first();
 Element symbol = new Element(Tag.valueOf("symbol"), "")
   .attr("id", id)
   .attr("viewBox", svg.attr("viewBox"));
 new ArrayList<>(svg.childNodes()).forEach(symbol::appendChild);
 return new Tuple(svg, symbol);
}

代码示例来源:origin: com.vaadin/vaadin-server

.getFragmentNodes();
Element mainDiv = new Element(Tag.valueOf("div"), "");
mainDiv.attr("id", context.getAppId());
mainDiv.addClass("v-app");
mainDiv.addClass(context.getThemeName());
mainDiv.addClass(
  fragmentNodes.add(new Element(Tag.valueOf("script"), "")
      .attr("type", "text/javascript").attr("src", pushJS));
fragmentNodes.add(new Element(Tag.valueOf("script"), "")
    .attr("type", "text/javascript")
    .attr("src", bootstrapLocation));
Element mainScriptTag = new Element(Tag.valueOf("script"), "")
    .attr("type", "text/javascript");

代码示例来源:origin: org.jsoup/jsoup

private ElementMeta createSafeElement(Element sourceEl) {
  String sourceTag = sourceEl.tagName();
  Attributes destAttrs = new Attributes();
  Element dest = new Element(Tag.valueOf(sourceTag), sourceEl.baseUri(), destAttrs);
  int numDiscarded = 0;
  Attributes sourceAttrs = sourceEl.attributes();
  for (Attribute sourceAttr : sourceAttrs) {
    if (whitelist.isSafeAttribute(sourceTag, sourceEl, sourceAttr))
      destAttrs.put(sourceAttr);
    else
      numDiscarded++;
  }
  Attributes enforcedAttrs = whitelist.getEnforcedAttributes(sourceTag);
  destAttrs.addAll(enforcedAttrs);
  return new ElementMeta(dest, numDiscarded);
}

代码示例来源:origin: dhanji/sitebricks

Element element = ((Element) node);
StringBuilder accum = new StringBuilder();
accum.append("<").append(element.tagName());
for (Attribute attribute: element.attributes()) {
  if (!(attribute.getKey().startsWith("_"))) {
    accum.append(" ");
if (element.childNodes().isEmpty() && element.tag().isEmpty()) {
  accum.append(" />");
} else {

代码示例来源:origin: com.google.sitebricks/sitebricks

Tag tag = Tag.valueOf(tagName);
Element child = new Element(tag, baseUri, attributes);
annotate(child);
boolean isEmptyElement = tag.isEmpty(); // empty element if empty tag (e.g. img) or self-closed el (<div/>
if (tq.matchChomp("/>")) { // close empty element or tag
 isEmptyElement = true;
if (tag.isData()) {
 String data = tq.chompTo("</" + tagName);
 tq.chompTo(">");
if (child.tagName().equals("base")) {
 String href = child.absUrl("href");
 if (!Strings.empty(href)) { // ignore <base target> etc
  baseUri = href;

代码示例来源:origin: basis-technology-corp/Java-readability

private void handleDoubleBr() {
  Elements doubleBrs = document.select("br + br");
  for (Element br : doubleBrs) {
    // we hope that there's a 'p' up there....
    Elements parents = br.parents();
    Element parent = null;
    for (Element aparent : parents) {
      if (aparent.tag().getName().equals("p")) {
        parent = aparent;
        break;
      }
    }
    if (parent == null) {
      parent = br.parent();
      parent.wrap("<p></p>");
    }
    // now it's safe to make the change.
    String inner = parent.html();
    inner = Patterns.REPLACE_BRS.matcher(inner).replaceAll("</p><p>");
    parent.html(inner);
  }
}

相关文章