本文整理了Java中org.jsoup.nodes.Element.getElementsByAttribute()
方法的一些代码示例,展示了Element.getElementsByAttribute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getElementsByAttribute()
方法的具体详情如下:
包路径:org.jsoup.nodes.Element
类名称:Element
方法名:getElementsByAttribute
[英]Find elements that have a named attribute set. Case insensitive.
[中]查找具有命名属性集的元素。不区分大小写。
代码示例来源:origin: astamuse/asta4d
public Elements getElementsByAttribute(String key) {
return originElement.getElementsByAttribute(key);
}
代码示例来源:origin: Cognifide/knotx
private static JsonObject getAdapterParams(Element scriptDocument) {
return Optional.ofNullable(scriptDocument
.getElementsByAttribute(FORM_ADAPTER_PARAMS).first())
.map(element -> element.attr(FORM_ADAPTER_PARAMS))
.map(JsonObject::new)
.orElse(null);
}
代码示例来源:origin: Cognifide/knotx
private static String getAdapterName(Fragment fragment, Element scriptDocument) {
return Optional.ofNullable(scriptDocument
.getElementsByAttribute(FORM_ACTION_ATTR).first())
.map(element -> element.attr(FORM_ACTION_ATTR))
.orElseThrow(() -> {
LOGGER.error("Could not find action adapter name in fragment [{}].",
fragment);
return new NoSuchElementException("Could not find action adapter name");
});
}
代码示例来源:origin: crazyacking/zeekEye
private static RePost parse(Element repostEl, String weiboID) {
RePost rePost = new RePost();
try {
//一部分人的ID并不是数字串,而是个性域名,这部分也尚待处理
//如:/u/123245 和 /kaifulee
String tempAuthor = repostEl.getElementsByAttribute("href").get(0).attr("href");
rePost.setAuthor(tempAuthor.substring(tempAuthor.lastIndexOf("/") + 1, tempAuthor.lastIndexOf("?")));
//获取一条评论内的有效内容,包括@的人
//因为内容和时间的标签和发布者的标签并列在一起,所以要截前后片段
String tempContent = repostEl.toString();
String tempContentString = tempContent.substring(tempContent.indexOf(">:") + 2, tempContent.indexOf("<span class="));
rePost.setContent(tempContentString.substring(0, tempContentString.indexOf(" ")));
//获取时间
rePost.setTime(Utils.parseDate(repostEl.getElementsByClass("ct").get(0).text().split("来自")[0]));
} catch (Exception e) {
rePost = null;
logger.error("Not a valid rePost item: " + repostEl);
}
return rePost;
}
代码示例来源:origin: crazyacking/zeekEye
private static Comment parse(Element commentEl, String weiboID) {
Comment comment = new Comment();
try {
comment.setId(commentEl.attr("id").substring(2));
//一部分人的ID并不是数字串,而是个性域名,这部分也尚待处理
//如:/u/123245 和 /kaifulee
String tempAuthor = commentEl.getElementsByAttribute("href").get(0).attr("href");
comment.setAuthor(tempAuthor.substring(tempAuthor.lastIndexOf("/") + 1, tempAuthor.lastIndexOf("?")));
//获取一条评论内的有效内容,包括@的人
String tempContent = commentEl.getElementsByClass("ctt").get(0).toString();
comment.setContent(tempContent.substring(18, tempContent.length() - 7));
comment.setTime(Utils.parseDate(commentEl.getElementsByClass("ct").get(0).text().split("来自")[0]));
} catch (Exception e) {
comment = null;
logger.error("Not a valid comment item: " + commentEl);
}
return comment;
}
代码示例来源:origin: stackoverflow.com
Elements childNodes = parentNode.getElementsByAttribute("data-ds-appid");
for(Element alink : childNodes)
代码示例来源:origin: Cognifide/knotx
@Override
public String transform(String content, String formIdAttrName, String formIdAttrValue) {
Element scriptContentDocument = FragmentContentExtractor.unwrapContent(content);
Element actionFormElement = scriptContentDocument.getElementsByAttribute(FORM_ACTION_ATTR).first();
LOGGER.debug("Changing form with identifier [{}]", formIdAttrValue);
addHiddenInputTag(actionFormElement, formIdAttrName, formIdAttrValue);
clearFromActionAttributes(actionFormElement);
return getFragmentContent(content, scriptContentDocument);
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-tool-standards-validator
/**
* CSS should be placed in linked files and not mixed with the HTML source code.
*/
public void validateRpd9s1()
{
assertTrue(Type.ERROR, "rpd9s1.attr", getElement(ELEM_BODY).getElementsByAttribute(STYLE).isEmpty());
assertTrue(Type.ERROR, "rpd9s1.tag", getElement(ELEM_BODY).getElementsByTag(STYLE).isEmpty());
}
内容来源于网络,如有侵权,请联系作者删除!