org.jsoup.nodes.Element.baseUri()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(136)

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

Element.baseUri介绍

暂无

代码示例

代码示例来源:origin: code4craft/webmagic

@Override
public List<String> selectList(Element element) {
  Elements elements = element.select("a");
  List<String> links = new ArrayList<String>(elements.size());
  for (Element element0 : elements) {
    if (!StringUtil.isBlank(element0.baseUri())) {
      links.add(element0.attr("abs:href"));
    } else {
      links.add(element0.attr("href"));
    }
  }
  return links;
}

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

/**
 * Add inner HTML to this element. The supplied HTML will be parsed, and each node appended to the end of the children.
 * @param html HTML to add inside this element, after the existing HTML
 * @return this element
 * @see #html(String)
 */
public Element append(String html) {
  Validate.notNull(html);
  List<Node> nodes = Parser.parseFragment(html, this, baseUri());
  addChildren(nodes.toArray(new Node[nodes.size()]));
  return this;
}

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

/**
 * Add inner HTML into this element. The supplied HTML will be parsed, and each node prepended to the start of the element's children.
 * @param html HTML to add inside this element, before the existing HTML
 * @return this element
 * @see #html(String)
 */
public Element prepend(String html) {
  Validate.notNull(html);
  
  List<Node> nodes = Parser.parseFragment(html, this, baseUri());
  addChildren(0, nodes.toArray(new Node[nodes.size()]));
  return this;
}

代码示例来源:origin: deeplearning4j/dl4j-examples

/**
 * Get a list of all URLs in a page for zip files
 */
public static List<String> getZipUrlsFromPage(String url) {
  List<String> out = new ArrayList<>();
  try {
    Document doc = Jsoup.connect(url).get();
    Elements links = doc.select("a[href]");
    for (Element e : links) {
      String s = e.attr("href");
      if (s.endsWith(".zip")) {
        if (s.startsWith("http")) {
          //Absolute link
          out.add(s);
        } else {
          //Relative link
          out.add(e.baseUri() + s);
        }
      }
    }
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  return out;
}

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

/**
 * Create a new element by tag name, and add it as the first child.
 * 
 * @param tagName the name of the tag (e.g. {@code div}).
 * @return the new element, to allow you to add content to it, e.g.:
 *  {@code parent.prependElement("h1").attr("id", "header").text("Welcome");}
 */
public Element prependElement(String tagName) {
  Element child = new Element(Tag.valueOf(tagName), baseUri());
  prependChild(child);
  return child;
}

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

/**
 * Create a new element by tag name, and add it as the last child.
 * 
 * @param tagName the name of the tag (e.g. {@code div}).
 * @return the new element, to allow you to add content to it, e.g.:
 *  {@code parent.appendElement("h1").attr("id", "header").text("Welcome");}
 */
public Element appendElement(String tagName) {
  Element child = new Element(Tag.valueOf(tagName), baseUri());
  appendChild(child);
  return child;
}

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

@Override
public boolean matches(Element root, Element element) {
  if (element instanceof PseudoTextElement)
    return true;
  List<TextNode> textNodes = element.textNodes();
  for (TextNode textNode : textNodes) {
    PseudoTextElement pel = new PseudoTextElement(
      org.jsoup.parser.Tag.valueOf(element.tagName()), element.baseUri(), element.attributes());
    textNode.replaceWith(pel);
    pel.appendChild(textNode);
  }
  return false;
}

代码示例来源: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: k9mail/k-9

public void head(Node source, int depth) {
  if (elementToSkip != null) {
    return;
  }
  if (source instanceof Element) {
    Element sourceElement = (Element) source;
    if (isSafeTag(sourceElement)) {
      String sourceTag = sourceElement.tagName();
      Attributes destinationAttributes = sourceElement.attributes().clone();
      Element destinationChild = new Element(Tag.valueOf(sourceTag), sourceElement.baseUri(), destinationAttributes);
      destination.appendChild(destinationChild);
      destination = destinationChild;
    } else if (source != root) {
      elementToSkip = sourceElement;
    }
  } else if (source instanceof TextNode) {
    TextNode sourceText = (TextNode) source;
    TextNode destinationText = new TextNode(sourceText.getWholeText(), source.baseUri());
    destination.appendChild(destinationText);
  } else if (source instanceof DataNode && isSafeTag(source.parent())) {
    DataNode sourceData = (DataNode) source;
    DataNode destinationData = new DataNode(sourceData.getWholeData(), source.baseUri());
    destination.appendChild(destinationData);
  }
}

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

new DataNode(builder.toString(), mainScriptTag.baseUri()));
fragmentNodes.add(mainScriptTag);

代码示例来源:origin: astamuse/asta4d

public String baseUri() {
  return originElement.baseUri();
}

代码示例来源:origin: stackoverflow.com

for (Element link : links) 
 System.out.println(Jsoup.connect(link.baseUri()).get());

代码示例来源:origin: us.codecraft/webmagic-core

@Override
public List<String> selectList(Element element) {
  Elements elements = element.select("a");
  List<String> links = new ArrayList<String>(elements.size());
  for (Element element0 : elements) {
    if (!StringUtil.isBlank(element0.baseUri())) {
      links.add(element0.attr("abs:href"));
    } else {
      links.add(element0.attr("href"));
    }
  }
  return links;
}

代码示例来源:origin: com.cv4j.netdiscovery/netdiscovery-core

@Override
public List<String> selectList(Element element) {
  Elements elements = element.select("a");
  List<String> links = new ArrayList<String>(elements.size());
  for (Element element0 : elements) {
    if (!StringUtil.isBlank(element0.baseUri())) {
      links.add(element0.attr("abs:href"));
    } else {
      links.add(element0.attr("href"));
    }
  }
  return links;
}

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

private static Element createInlineJavaScriptElement(
    String javaScriptContents) {
  // defer makes no sense without src:
  // https://developer.mozilla.org/en/docs/Web/HTML/Element/script
  Element wrapper = createJavaScriptElement(null, false);
  wrapper.appendChild(
      new DataNode(javaScriptContents, wrapper.baseUri()));
  return wrapper;
}

代码示例来源:origin: wzmyyj/ZYMK

public static TyBox transToTy(Element body) {
  String base = body.baseUri();
  String title = body.getElementsByClass("mk-header").get(0)
      .getElementsByClass("title").get(0).text();
  String next = body.getElementsByClass("mk-pages").get(0)
      .getElementsByClass("next").get(0).absUrl("href");
  Element comic_sort = body.getElementsByClass("comic-sort").get(0);
  List<BookBean> books = new ArrayList<>();
  Elements items = comic_sort.getElementsByClass("comic-item");
  if (items != null || items.size() > 0) {
    for (Element item : items) {
      books.add(getBook(item));
    }
  }
  TyBox box = new TyBox(base, title, next, books);
  return box;
}

代码示例来源:origin: org.apache.sling/org.apache.sling.hapi.client

@Override
public Document submit(Iterable<NameValuePair> values) throws ClientException {
  if (el.tagName().equalsIgnoreCase("form")) {
    String action = el.attr("abs:action");
    if (action.length() == 0) {
      action = el.baseUri();
    }
    String method = el.attr("method");
    if (method.length() == 0 || method.equalsIgnoreCase("get")) {
      FormValues query = new FormValues(el, values);
      String url = action + (action.contains("?") ? "?" : "&") + query.toString();
      return document.client.enter(url);
    }
    if (method.equalsIgnoreCase("post")) {
      String enctype = el.attr("enctype");
      FormValues v = new FormValues(el, values);
      if (enctype.length() == 0 || enctype.equalsIgnoreCase("application/x-www-form-urlencoded")) {
        return document.client.post(action, v.toUrlEncodedEntity());
      } else if (enctype.equalsIgnoreCase("multipart/form-data")) {
        return document.client.post(action, v.toMultipartEntity());
      }
      throw new ClientException("Unsupported form enctype: " + enctype);
    }
    throw new ClientException("Unsupported form method: " + method);
  }
  throw new ClientException("The item is not a form");
}

代码示例来源:origin: GistLabs/mechanize

@Override
protected void loadPage() throws Exception {
  Document jsoup = Jsoup.parse(getInputStream(), getContentEncoding(response), getUri());
  setBaseUri(jsoup.head().baseUri());
  this.htmlElements = new HtmlElements(this, jsoup);
}

代码示例来源:origin: org.kantega.openaksess/openaksess-core

private static Element createSafeElement(Element sourceEl) {
  String sourceTag = sourceEl.tagName();
  org.jsoup.nodes.Attributes destAttrs = new org.jsoup.nodes.Attributes();
  Element dest = new Element(Tag.valueOf(sourceTag), sourceEl.baseUri(), destAttrs);
  org.jsoup.nodes.Attributes sourceAttrs = sourceEl.attributes();
  for (Attribute sourceAttr : sourceAttrs) {
      destAttrs.put(sourceAttr);
  }
  return dest;
}

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

private static Element createDependencyElement(
    BootstrapUriResolver resolver, LoadMode loadMode,
    JsonObject dependency, Dependency.Type type) {
  boolean inlineElement = loadMode == LoadMode.INLINE;
  String url = dependency.hasKey(Dependency.KEY_URL)
      ? resolver.resolveVaadinUri(
          dependency.getString(Dependency.KEY_URL))
      : null;
  final Element dependencyElement;
  switch (type) {
  case STYLESHEET:
    dependencyElement = createStylesheetElement(url);
    break;
  case JAVASCRIPT:
    dependencyElement = createJavaScriptElement(url, !inlineElement);
    break;
  case HTML_IMPORT:
    dependencyElement = createHtmlImportElement(url);
    break;
  default:
    throw new IllegalStateException(
        "Unsupported dependency type: " + type);
  }
  if (inlineElement) {
    dependencyElement.appendChild(
        new DataNode(dependency.getString(Dependency.KEY_CONTENTS),
            dependencyElement.baseUri()));
  }
  return dependencyElement;
}

相关文章

微信公众号

最新文章

更多

Element类方法