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

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

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

Element.selectFirst介绍

[英]Find the first Element that matches the Selector CSS query, with this element as the starting context.

This is effectively the same as calling element.select(query).first(), but is more efficient as query execution stops on the first hit.
[中]查找与选择器CSS查询匹配的第一个元素,该元素作为起始上下文。
这实际上与调用元素相同。选择(查询)。first(),但由于查询执行在第一次命中时停止,因此效率更高。

代码示例

代码示例来源:origin: JpressProjects/jpress

/**
 * 判断空元素
 * 条件是 没有文本型内容 不包含图片、视频、音频数据、还没有Style或者class的标签
 *
 * @param element
 * @return
 */
private boolean elementIsEmpty(Element element) {
  return element.hasText() == false &&
      element.selectFirst("img") == null &&
      element.selectFirst("video") == null &&
      element.selectFirst("audio") == null &&
      element.hasAttr("style") == false &&
      element.hasAttr("class") == false;
}

代码示例来源:origin: erickok/transdroid-search

@Override
protected SearchResult buildSearchResult(Element torrentElement) {
  final Element groupInfo = torrentElement.selectFirst("div[class^=group_info]");
  final Element nameElement = groupInfo.selectFirst("div > a");
  final String title = nameElement.text();
  final String torrentUrl = BASE_URL + groupInfo.selectFirst("div > span > a").attr("href");
  final String detailsUrl = BASE_URL + nameElement.attr("href");
  Date added;
  try {
    added = DATE_FORMAT.parse(torrentElement.selectFirst("span[class='time tooltip']").attr("title"));
  } catch (ParseException e) {
    added = null;
  }
  final Elements numberColumns = torrentElement.select("td[class^='number_column']");
  final String size = numberColumns.get(0).text();
  final int seeds = Integer.valueOf(numberColumns.get(2).text());
  final int leechers = Integer.valueOf(numberColumns.get(3).text());
  return new SearchResult(title, torrentUrl, detailsUrl, size, added, seeds, leechers);
}

代码示例来源:origin: erickok/transdroid-search

@Override
protected SearchResult buildSearchResult(Element torrentElement) {
 final Element titleElement = torrentElement.selectFirst("div.postTitle a");
 final String title = titleElement.text();
 final String detailsUrl = BASE_URL + titleElement.attr("href");
 final String contentText = torrentElement.selectFirst("div.postContent > p:last-child").text();
 final Matcher matcher = CONTENT_PATTERN.matcher(contentText);
 final Date added;
 final String size;
 if (matcher.matches()) {
  added = DateUtils.parseDate(DATE_FORMAT, matcher.group(1));
  size = matcher.group(2);
 } else {
  added = null;
  size = null;
 }
 // There is no proper torrent download link on the search results page so use the datailUrl
 // instead. Will fetch the actual torrentUrl in getTorrentFile()
 // Site does not support seeders/leechers
 return new SearchResult(title, detailsUrl, detailsUrl, size, added, 0, 0);
}

代码示例来源:origin: slartus/4pdaClient-plus

public static ArrayList<DevModel> parseModels(IHttpClient client, String brandUrl) throws Throwable {
  ArrayList<DevModel> res = new ArrayList<>();
  String pageBody = client.performGet(brandUrl + "/all");
  Document doc = Jsoup.parse(pageBody);
  Elements con = doc.selectFirst("div.device-frame").getElementById("device-brand-items-list").children();
  for (int i = 0; i < con.size(); i++) {
    Element box = con.get(i).selectFirst("div.box-holder");
    if (box != null) {
      String link = box.selectFirst("a").attr("href");
      String title = box.selectFirst("a").attr("title");
      String image = box.selectFirst("img").attr("src");
      DevModel model = new DevModel(link, title);
      model.setImgUrl(image);
      model.setDescription(box.select(".frame .specifications-list").first().text());
      res.add(model);
    }
  }
  return res;
}

代码示例来源:origin: freedom10086/Ruisi

for (int i = 0; i < subs.size() - 1; i++) {
    Element forum = subs.get(i);
    Element a = forum.selectFirst("tr > td > h2 > a");
    String link = a.attr("href");
    int fid = Integer.valueOf(GetId.getId("fid=", link));
  type = "置顶";
} else {
  Element element = li.selectFirst("tr > th > span.xi1");
  if (element != null && element.text().contains("回帖奖励")) {
    type = "金币:" + GetId.getNumber(element.text());
  } else {
    Element e = li.selectFirst(".icn a");
    if (e != null) {
      String title = e.attr("title");
Element titleElement = li.selectFirst("tr > th > a.s.xst");
if (titleElement == null) continue;
String title = titleElement.text();
Element authorNode = li.selectFirst("tr > td > cite > a");
if (authorNode == null) {
  author = "未知";
Element timeNode = li.selectFirst("tr > td > em");
if (timeNode == null) {
  time = "未知时间";

代码示例来源:origin: slartus/4pdaClient-plus

Element l = tdElement.selectFirst("a");
if (l != null) {
  Uri ur = Uri.parse(l.attr("href"));
l = tdElement.selectFirst("a");
if (l != null) {
  rep.setSourceUrl(l.attr("href"));

代码示例来源:origin: chenerzhu/proxy-pool

@Override
public void parsePage(WebPage webPage) {
  Elements elements = webPage.getDocument().getElementsByClass("spy1xx");
  Element element;
  ProxyIp proxyIp;
  for (int i = 1; i < elements.size(); i++) {
    try {
      element = elements.get(i);
      proxyIp = new ProxyIp();
      proxyIp.setIp(element.child(0).selectFirst(".spy14").text());
      int port = getPort(element);
      if (port == -1) {
        continue;
      }
      proxyIp.setPort(port);
      proxyIp.setCountry(element.child(3).selectFirst(".spy14").text());
      proxyIp.setLocation(element.child(3).text());
      proxyIp.setType(element.child(1).text());
      proxyIp.setAnonymity(element.child(2).text());
      proxyIp.setAvailable(true);
      proxyIp.setCreateTime(new Date());
      proxyIp.setLastValidateTime(new Date());
      proxyIp.setValidateCount(0);
      proxyIpQueue.offer(proxyIp);
    } catch (Exception e) {
      log.error("spysOneCrawlerJob error:{0}",e);
    }
  }
}

相关文章

微信公众号

最新文章

更多

Element类方法