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

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

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

Element.getElementsByAttributeValue介绍

[英]Find elements that have an attribute with the specific value. Case insensitive.
[中]查找具有具有特定值的属性的元素。不区分大小写。

代码示例

代码示例来源:origin: loklak/loklak_server

info=infos.get(i);
if (info.getElementsByAttributeValueContaining("href", "loc=infblog").size()==0) {
  profile=info.getElementsByAttributeValue("class","pt_detail").first().text().trim();
  obj.put("pro", profile);
  switch(info.getElementsByAttributeValue("class", "pt_title S_txt2").first().text()){
  case "Nickname\uff1a":
    obj.put("username", profile);

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

public Elements getElementsByAttributeValue(String key, String value) {
  return originElement.getElementsByAttributeValue(key, value);
}

代码示例来源:origin: XiqingLiu/GEEK

public static List<RNApiSub> getApiSub(String groupId) {
    ArrayList<RNApiSub> datas = new ArrayList<>();
    try {
      Document document = Jsoup.connect(ROOT_URL).get();
      Element apiGroup = document.getElementsByAttributeValue("data-reactid", groupId).get(0);
      Element apiSub = apiGroup.getElementsByClass("apiSub").get(0);
      Elements lis = apiSub.getElementsByAttributeValue("target", "_self");
      for (int i = 0; i < lis.size(); i++) {
        Element element = lis.get(i);
        String reactId = element.attr("data-reactid");
        String name = element.text();
        String url = element.attr("abs:href");
        datas.add(new RNApiSub(Integer.parseInt(reactId), name, url, Long.parseLong(groupId)));
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    return datas;
  }
}

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

public static Instructions getInstructions(final String html) {
   Instructions instr = new Instructions();
   try {
     Element body = Jsoup.connect(html).get().body();
     Element elem = body.getElementsByAttributeValue("itemprop", "recipeInstructions").first();
     for (Element e : elem.getElementsByTag("li")) {
       instr.add(e.text());
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
   return instr;
 }

代码示例来源:origin: com.cognifide.aet/jobs

@Override
 public W3cHtml5Issue apply(Node child) {
  if (!(child instanceof Element)) {
   return null;
  }
  Element element = (Element) child;
  W3cHtml5IssueType issueType = W3cHtml5IssueType
    .valueOf(StringUtils.removeStart(element.attr("class"), "msg_").toUpperCase());
  String message = element.getElementsByAttributeValue("class", "msg").html();
  String additionalInfo = element.child(1).html();
  return new W3cHtml5Issue(0, 0, message, StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY,
    additionalInfo, issueType);

 }
}

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

System.out.println("Item name: " + row.child(0).text()); // Milk will be here somewhere
System.out.println("  Item price by column number: " + row.child(1).text());
System.out.println("  Item price by column class:  " + row.getElementsByAttributeValue("class", "priceValue").get(0).text());

代码示例来源:origin: Cognifide/aet

@Override
 public W3cHtml5Issue apply(Node child) {
  if (!(child instanceof Element)) {
   return null;
  }
  Element element = (Element) child;
  W3cHtml5IssueType issueType = W3cHtml5IssueType
    .valueOf(StringUtils.removeStart(element.attr("class"), "msg_").toUpperCase());
  String message = element.getElementsByAttributeValue("class", "msg").html();
  String additionalInfo = element.child(1).html();
  return new W3cHtml5Issue(0, 0, message, StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY,
    additionalInfo, issueType);

 }
}

代码示例来源:origin: florent37/RxRetroJsoup

@Override
  public void subscribe(ObservableEmitter<Element> observableEmitter) throws Exception {
    final Elements elements = element.getElementsByAttributeValue(key, value);
    if (elements.isEmpty() && exceptionIfNotFound) {
      observableEmitter.onError(new NotFoundException(key + " " + value, element.toString()));
    } else {
      for (Element e : elements) {
        observableEmitter.onNext(e);
      }
      observableEmitter.onComplete();
    }
  }
});

代码示例来源:origin: com.github.florent37/rxjsoup

@Override
  public void subscribe(ObservableEmitter<Element> observableEmitter) throws Exception {
    final Elements elements = element.getElementsByAttributeValue(key, value);
    if (elements.isEmpty() && exceptionIfNotFound) {
      observableEmitter.onError(new NotFoundException(key + " " + value, element.toString()));
    } else {
      for (Element e : elements) {
        observableEmitter.onNext(e);
      }
      observableEmitter.onComplete();
    }
  }
});

代码示例来源:origin: com.infotel.seleniumRobot/core

field = By.ByName.class.getDeclaredField("name");
field.setAccessible(true);
foundElements.addAll(cachedElement.getElementsByAttributeValue("name", (String)field.get(by))
          .stream()
          .map(CachedHtmlElement::new)

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

private static void handleInitialPageSettings(BootstrapContext context,
    Element head, InitialPageSettings initialPageSettings) {
  if (initialPageSettings.getViewport() != null) {
    Elements viewport = head.getElementsByAttributeValue("name",
        VIEWPORT);
    if (!viewport.isEmpty() && viewport.size() == 1) {
      viewport.get(0).attr(CONTENT_ATTRIBUTE,
          initialPageSettings.getViewport());
    } else {
      head.appendElement(META_TAG).attr("name", VIEWPORT).attr(
          CONTENT_ATTRIBUTE, initialPageSettings.getViewport());
    }
  }
  initialPageSettings.getInline(InitialPageSettings.Position.PREPEND)
      .stream()
      .map(dependency -> createDependencyElement(context, dependency))
      .forEach(
          element -> insertElements(element, head::prependChild));
  initialPageSettings.getInline(InitialPageSettings.Position.APPEND)
      .stream()
      .map(dependency -> createDependencyElement(context, dependency))
      .forEach(element -> insertElements(element, head::appendChild));
  initialPageSettings.getElement(InitialPageSettings.Position.PREPEND)
      .forEach(
          element -> insertElements(element, head::prependChild));
  initialPageSettings.getElement(InitialPageSettings.Position.APPEND)
      .forEach(element -> insertElements(element, head::appendChild));
}

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

ListOfIngredients tmp = new ListOfIngredients();
  try {
    Element body = Jsoup.connect(html).get().body();

    try {
      for (Element elem : body.getElementsByAttributeValue("itemprop", "ingredients")) {
        Elements ingredientAmtElements = elem.getElementsByClass("ingredient-amount");
        String amount = null;
        if (!ingredientAmtElements.isEmpty()) {
          amount = ingredientAmtElements.first().text();
        }
        String ingredient = elem.getElementsByClass("ingredient-name").first().text();
        if (!ingredient.equals("\u00a0")) {
          tmp.add(new Ingredient(amount, ingredient));
        }
      }
    } catch (NullPointerException e) {
      e.printStackTrace();
    }
  } catch (IOException e1) {
    e1.printStackTrace();
  }

  return tmp;
}

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

String point = el.attr("point");
if (point.equals("xbmc.addon.metadata")) {
 Elements desc = el.getElementsByAttributeValue("lang", Locale.getDefault().getLanguage());
 if (desc.size() == 0) {
  desc = el.getElementsByAttributeValue("lang", "en");

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

for (Element a : tr.getElementsByAttributeValue("valign", "middle")) {
 String act = a.toString();
 String aname = StrgUtils.substr(act, "alt=\"(.*?)\"");

代码示例来源:origin: asciidoctor/asciidoctorj

@Test
public void should_create_toc_with_treeprocessor() {
  asciidoctor.javaExtensionRegistry().treeprocessor(new Treeprocessor() {
    @Override
    public org.asciidoctor.ast.Document process(org.asciidoctor.ast.Document document) {
      List<StructuralNode> blocks = document.getBlocks();
      for (StructuralNode block : blocks) {
        for (StructuralNode block2 : block.getBlocks()) {
          if (block2 instanceof Section)
            System.out.println(((Section) block2).getId());
        }
      }
      return document;
    }
  });
  String content = asciidoctor.convertFile(
      classpath.getResource("documentwithtoc.adoc"),
      options().headerFooter(true).toFile(false).safe(SafeMode.UNSAFE).get());
  org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
  Element toc = doc.getElementById("toc");
  assertThat(toc, notNullValue());
  Elements elements = toc.getElementsByAttributeValue("href", "#TestId");
  assertThat(elements.size(), is(1));
}

代码示例来源:origin: asciidoctor/asciidoctorj

@Test
public void should_create_toc_with_treeprocessor() throws Exception {
  this.asciidoctor.createGroup()
    .treeprocessor(new Treeprocessor() {
      @Override
      public Document process(Document document) {
        List<StructuralNode> blocks=document.getBlocks();
        for (StructuralNode block : blocks) {
          for (StructuralNode block2 : block.getBlocks()) {
            if(block2 instanceof Section)
              System.out.println(((Section) block2).getId());
          }
        }
        return document;
      }
    })
    .register();
  String content = asciidoctor.convertFile(
      classpath.getResource("documentwithtoc.adoc"),
      options().headerFooter(true).toFile(false).safe(SafeMode.UNSAFE).get());
  org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
  Element toc = doc.getElementById("toc");
  assertThat(toc, notNullValue());
  Elements elements = toc.getElementsByAttributeValue("href", "#TestId");
  assertThat(elements.size(), is(1));
}

相关文章

微信公众号

最新文章

更多

Element类方法