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

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

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

Element.val介绍

[英]Get the value of a form element (input, textarea, etc).
[中]获取表单元素的值(input、textarea等)。

代码示例

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

/**
 * Set the form element's value in each of the matched elements.
 * @param value The value to set into each matched element
 * @return this (for chaining)
 */
public Elements val(String value) {
  for (Element element : this)
    element.val(value);
  return this;
}

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

/**
 * Get the form element's value of the first matched element.
 * @return The form element's value, or empty if not set.
 * @see Element#val()
 */
public String val() {
  if (size() > 0)
    return first().val();
  else
    return "";
}

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

boolean set = false;
for (Element option: options) {
  data.add(HttpConnection.KeyVal.create(name, option.val()));
  set = true;
  Element option = el.select("option").first();
  if (option != null)
    data.add(HttpConnection.KeyVal.create(name, option.val()));
  final String val = el.val().length() >  0 ? el.val() : "on";
  data.add(HttpConnection.KeyVal.create(name, val));
data.add(HttpConnection.KeyVal.create(name, el.val()));

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

private void getElements(Elements elements, List<Map<String, Object>> resultList) {
  for (Element element : elements) {
    Map<String, Object> result = new HashMap<>();
    if(element.attributes().size() > 0) result.put("attributes", getAttributes(element));
    if(!element.data().isEmpty())result.put("data", element.data());
    if(element.hasText()) result.put("text", element.text());
    if(!element.val().isEmpty()) result.put("value", element.val());
    if(!element.tagName().isEmpty()) result.put("tagName", element.tagName());
    resultList.add(result);
  }
}

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

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

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

public Element val(String value) {
  return originElement.val(value);
}

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

public Document submitForm(Element formElement, Map<String, String> data) throws IOException {
  String src = formElement.attr("action");
  Elements inputElements = formElement.select("input");
  for (Element inputElement : inputElements) {
    if (!data.containsKey(inputElement.attr("name"))) {
      data.put(inputElement.attr("name"), inputElement.val());
    }
  }
  Connection.Response response = Jsoup.connect(src).method(Connection.Method.POST).data(data).execute();
  return response.parse();
}

代码示例来源:origin: hjw541988478/ZfsoftCampusAssit

public String parseViewStateParam(String viewstateHtml) {
  String stateVal = "";
  Document stateHeaderDoc = Jsoup.parse(viewstateHtml);
  Elements elements = stateHeaderDoc.getElementsByTag("input");
  for (Element element : elements) {
    if ("__VIEWSTATE".equals(element.attr("name"))) {
      stateVal = element.val();
      break;
    }
  }
  return stateVal;
}

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

protected void setSelectValue(Element select, String value) {
  for (Element opt : select.select("option")) {
    if (value.equals(opt.val())) {
      opt.attr("selected", "selected");
    } else {
      opt.removeAttr("selected");
    }
  }
}

代码示例来源:origin: hjw541988478/ZfsoftCampusAssit

private String parseParamsHeader(Document doc, String key) {
  Elements elements = doc.getElementsByTag("input");
  for (Element element : elements) {
    if (key.equals(element.attr("name"))) {
      return element.val();
    }
  }
  return "";
}

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

@Override
public Set<String> getSupportedLanguages() throws IOException {
  Set<String> langs = new HashSet<>();
  String html = httpGet(opac_url + "/Search/Advanced",
      getDefaultEncoding());
  Document doc = Jsoup.parse(html);
  if (doc.select("select[name=mylang]").size() > 0) {
    for (Element opt : doc.select("select[name=mylang] option")) {
      if (languageCodes.containsValue(opt.val())) {
        for (Map.Entry<String, String> lc : languageCodes.entrySet()) {
          if (lc.getValue().equals(opt.val())) {
            langs.add(lc.getKey());
            break;
          }
        }
      } else {
        langs.add(opt.val());
      }
    }
  }
  return langs;
}

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

private String parse_option_regex(Element inputTag) {
  String optStr = inputTag.val();
  String html = inputTag.parent().html();
  String result = optStr;
  String regex1 = "value=\"" + optStr + "\".*?>([^<]+)";
  String[] regexList = new String[]{regex1};
  for (String regex : regexList) {
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(html);
    if (matcher.find()) {
      result = matcher.group(1);
      result = result.replaceAll("&nbsp;", " ").trim();
      break;
    }
  }
  return result;
}

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

Document doc = Jsoup.parse("your html")
String selectedVal = null;
Elements options = doc.getElementsByAttributeValue("name", "Category").get(0).children();
for (Element option : options) {
  if (option.hasAttr("selected")) {
    selectedVal = option.val();
  }
}

代码示例来源:origin: Kaaz/DiscordBot

private void loadMemeOptions() {
    try {
      Document document = Jsoup.connect("https://memegen.link/").userAgent(BotConfig.USER_AGENT).get();
      if (document != null) {
        Elements fmls = document.select(".js-meme-selector option");
        if (!fmls.isEmpty()) {
          for (Element fml : fmls) {
            memeTypes.add(fml.val().toLowerCase());
          }
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

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

protected void addAdvancedSearchFields(List<SearchField> fields)
    throws IOException, JSONException {
  final String html = httpGet(getApiUrl() + "&mode=a", getDefaultEncoding());
  final Document doc = Jsoup.parse(html);
  final Elements options = doc.select("select#adv_search_crit_0").first().select("option");
  for (final Element option : options) {
    final SearchField field;
    if (SEARCH_FIELDS_FOR_DROPDOWN.contains(option.val())) {
      field = new DropdownSearchField();
      addDropdownValuesForField(((DropdownSearchField) field), option.val());
    } else {
      field = new TextSearchField();
      ((TextSearchField) field).setHint("");
    }
    field.setDisplayName(option.text());
    field.setId(option.val());
    field.setData(new JSONObject());
    field.getData().put("meaning", field.getId());
    fields.add(field);
  }
}

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

private void login(Account account) throws IOException, OpacErrorException {
  Document doc = Jsoup.parse(httpGet(opac_url + "/MyResearch/Home", getDefaultEncoding()));
  Element loginForm = doc.select("form[name=loginForm]").first();
  if (loginForm == null) return;
  FormBody.Builder builder = new FormBody.Builder()
      .add("username", account.getName())
      .add("password", account.getPassword());
  for (Element hidden : loginForm.select("input[type=hidden]")) {
    builder.add(hidden.attr("name"), hidden.val());
  }
  if (data.has("library")) {
    builder.add("library_select", data.optString("library"));
  }
  doc = Jsoup.parse(
      httpPost(opac_url + "/MyResearch/Home", builder.build(), getDefaultEncoding()));
  if (doc.select(".flash-message").size() > 0 &&
      doc.select("form[name=loginForm]").size() > 0) {
    throw new OpacErrorException(doc.select(".flash-message").text());
  }
}

代码示例来源:origin: actframework/actframework

private boolean verify(Verifier test, Object value) {
  if (test.verify(value)) {
    return true;
  }
  if (value instanceof Element) {
    Element e = (Element) value;
    if (test.verify(e.val())) {
      return true;
    }
    if (test.verify(e.text())) {
      return true;
    }
    if (test.verify(e.html())) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: org.actframework/act-e2e

private boolean verify(Verifier test, Object value) {
  if (test.verify(value)) {
    return true;
  }
  if (value instanceof Element) {
    Element e = (Element) value;
    if (test.verify(e.val())) {
      return true;
    }
    if (test.verify(e.text())) {
      return true;
    }
    if (test.verify(e.html())) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: org.actframework/act

private boolean verify(Verifier test, Object value) {
  if (test.verify(value)) {
    return true;
  }
  if (value instanceof Element) {
    Element e = (Element) value;
    if (test.verify(e.val())) {
      return true;
    }
    if (test.verify(e.text())) {
      return true;
    }
    if (test.verify(e.html())) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: actframework/actframework

private static boolean matches(Object a, Object b) {
  if ($.eq(a, b)) {
    return true;
  }
  if (!((b instanceof String) && (a instanceof Element))) {
    return false;
  }
  String test = S.string(b);
  Element element = (Element) a;
  // try html
  String html = element.html();
  if (S.eq(html, test, S.IGNORECASE)) {
    return true;
  }
  // try text
  String text = element.text();
  if (S.eq(text, test, S.IGNORECASE)) {
    return true;
  }
  // try val
  String val = element.val();
  if (S.eq(val, test, S.IGNORECASE)) {
    return true;
  }
  return false;
}

相关文章

Element类方法