本文整理了Java中org.jsoup.nodes.Document.getElementById()
方法的一些代码示例,展示了Document.getElementById()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Document.getElementById()
方法的具体详情如下:
包路径:org.jsoup.nodes.Document
类名称:Document
方法名:getElementById
暂无
代码示例来源:origin: seven332/EhViewer
/**
* Parse comments with html parser
*/
@NonNull
public static GalleryComment[] parseComments(Document document) {
try {
Element cdiv = document.getElementById("cdiv");
Elements c1s = cdiv.getElementsByClass("c1");
List<GalleryComment> list = new ArrayList<>(c1s.size());
for (int i = 0, n = c1s.size(); i < n; i++) {
GalleryComment comment = parseComment(c1s.get(i));
if (null != comment) {
list.add(comment);
}
}
return list.toArray(new GalleryComment[list.size()]);
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
e.printStackTrace();
return EMPTY_GALLERY_COMMENT_ARRAY;
}
}
代码示例来源:origin: seven332/EhViewer
/**
* Parse tag groups with html parser
*/
@NonNull
public static GalleryTagGroup[] parseTagGroups(Document document) {
try {
Element taglist = document.getElementById("taglist");
Elements tagGroups = taglist.child(0).child(0).children();
List<GalleryTagGroup> list = new ArrayList<>(tagGroups.size());
for (int i = 0, n = tagGroups.size(); i < n; i++) {
GalleryTagGroup group = parseTagGroup(tagGroups.get(i));
if (null != group) {
list.add(group);
}
}
return list.toArray(new GalleryTagGroup[list.size()]);
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
e.printStackTrace();
return EMPTY_GALLERY_TAG_GROUP_ARRAY;
}
}
代码示例来源:origin: seven332/EhViewer
public static String parse(String body) throws ParseException {
try {
Document d = Jsoup.parse(body, EhUrl.URL_FORUMS);
Element userlinks = d.getElementById("userlinks");
Element child = userlinks.child(0).child(0).child(0);
return child.attr("href");
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
throw new ParseException("Parse forums error", body);
}
}
}
代码示例来源:origin: seven332/EhViewer
public static Result parse(String body) throws ParseException {
try {
Result result = new Result();
Document d = Jsoup.parse(body);
Element profilename = d.getElementById("profilename");
result.displayName = profilename.child(0).text();
try {
result.avatar = profilename.nextElementSibling().nextElementSibling().child(0).attr("src");
if (TextUtils.isEmpty(result.avatar)) {
result.avatar = null;
} else if (!result.avatar.startsWith("http")) {
result.avatar = EhUrl.URL_FORUMS + result.avatar;
}
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
Log.i(TAG, "No avatar");
}
return result;
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
throw new ParseException("Parse forums error", body);
}
}
代码示例来源:origin: seven332/EhViewer
@SuppressWarnings("ConstantConditions")
public static List<GalleryInfo> parse(String body) throws ParseException {
try {
List<GalleryInfo> galleryInfoList = new ArrayList<>(15);
Document d = Jsoup.parse(body);
Element pp = d.getElementById("pp");
Elements id1List = pp.getElementsByClass("id1");
for (int i = 0, n = id1List.size(); i < n; i++) {
GalleryInfo galleryInfo = new GalleryInfo();
Element id1 = id1List.get(i);
Element id3 = JsoupUtils.getElementByClass(id1, "id3");
Element temp = JsoupUtils.getElementByTag(id3, "a");
String url = temp.attr("href");
GalleryDetailUrlParser.Result result = GalleryDetailUrlParser.parse(url);
galleryInfo.gid = result.gid;
galleryInfo.token = result.token;
temp = JsoupUtils.getElementByTag(temp, "img");
galleryInfo.thumb = EhUtils.handleThumbUrlResolution(temp.attr("src"));
galleryInfo.title = temp.attr("title");
galleryInfo.generateSLang();
galleryInfoList.add(galleryInfo);
}
return galleryInfoList;
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
throw new ParseException("Parse whats hot error", body);
}
}
}
代码示例来源:origin: seven332/EhViewer
/**
* Parse large previews with regular expressions
*/
private static LargePreviewSet parseLargePreviewSet(Document d, String body) throws ParseException {
try {
LargePreviewSet largePreviewSet = new LargePreviewSet();
Element gdt = d.getElementById("gdt");
Elements gdtls = gdt.getElementsByClass("gdtl");
int n = gdtls.size();
if (n <= 0) {
throw new ParseException("Can't parse large preview", body);
}
for (int i = 0; i < n; i++) {
Element element = gdtls.get(i).child(0);
String pageUrl = element.attr("href");
element = element.child(0);
String imageUrl = element.attr("src");
if (Settings.getFixThumbUrl()) {
imageUrl = EhUrl.getFixedPreviewThumbUrl(imageUrl);
}
int index = Integer.parseInt(element.attr("alt")) - 1;
largePreviewSet.addItem(index, imageUrl, pageUrl);
}
return largePreviewSet;
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
e.printStackTrace();
throw new ParseException("Can't parse large preview", body);
}
}
代码示例来源:origin: loklak/loklak_server
result.put("meetup_type", meetupType);
groupDescription = meetupHTML.getElementById("groupDesc").text();
result.put("group_description", groupDescription);
result.put("group_imageLink", imageLink);
topicList = meetupHTML.getElementById("topic-box-2012").getElementsByTag("a");
recentMeetupsSection = meetupHTML.getElementById("recentMeetups").getElementsByTag("p");
代码示例来源:origin: TEAMMATES/teammates
@Test
public void testFrontendBackendTimezoneDatabasesAreConsistent() {
// ensure the front-end and the back-end have the same timezone database version
Document pageSource = Jsoup.parse(browser.driver.getPageSource());
String javaOffsets = processOffsets(pageSource.getElementById("tz-java").text());
String momentOffsets = processOffsets(pageSource.getElementById("tz-moment").text());
assertEquals(pageSource.getElementById("tzversion-java").text(),
pageSource.getElementById("tzversion-moment").text());
if (!javaOffsets.equals(momentOffsets)) {
// Show diff when running test in Gradle
assertEquals("<expected>" + System.lineSeparator() + javaOffsets + "</expected>",
"<actual>" + System.lineSeparator() + momentOffsets + "</actual>");
}
}
代码示例来源:origin: TEAMMATES/teammates
@Test
public void testTimezoneDatabasesAreUpToDate() {
// ensure the timezone databases are up-to-date
String currentTzVersion = Jsoup.parse(browser.driver.getPageSource()).getElementById("tzversion-moment").text();
browser.driver.get(IANA_TIMEZONE_DATABASE_URL);
Document tzReleasePage = Jsoup.parse(browser.driver.getPageSource());
String latestTzVersion = tzReleasePage.getElementById("version").text();
if (!currentTzVersion.equals(latestTzVersion)) {
// find the release day
String releaseDateString = tzReleasePage.getElementById("date").text();
Pattern datePattern = Pattern.compile("\\(Released (.+)\\)");
Matcher matcher = datePattern.matcher(releaseDateString);
assertTrue(matcher.find());
LocalDate releaseDate = LocalDate.parse(matcher.group(1), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
LocalDate nowDate = Instant.now().atZone(Const.DEFAULT_TIME_ZONE).toLocalDate();
assertTrue(
"The timezone database version is not up-to-date for more than " + DAYS_TO_UPDATE_TZ + " days,"
+ " please update them according to the maintenance guide.",
releaseDate.plusDays(DAYS_TO_UPDATE_TZ).isAfter(nowDate));
}
}
代码示例来源:origin: spring-projects/spring-roo
private Document mergeCreateDetailsView(String templateName, Document loadExistingDoc,
ViewContext ctx, EntityItem entityItem, DetailEntityItem detail) {
Element elementDetail = loadExistingDoc.getElementById(detail.getEntityItemId());
if (elementDetail != null && elementDetail.hasAttr("data-z")
&& elementDetail.attr("data-z").equals("user-managed")) {
detail.setUserManaged(true);
detail.setCodeManaged(elementDetail.outerHtml());
ctx.addExtraParameter("detail", detail);
}
ctx.addExtraParameter("userManagedComponents", mergeStructure(loadExistingDoc));
return process(templateName, ctx);
}
代码示例来源:origin: spring-projects/spring-roo
@Override
public Document mergeMenu(String templateName, Document loadExistingDoc,
ViewContext<ThymeleafMetadata> ctx, List<MenuEntry> menuEntries) {
for (MenuEntry menuEntry : menuEntries) {
// Get field code if data-z attribute value is equals to
// user-managed
Element elementMenu = loadExistingDoc.getElementById(menuEntry.getId().concat("-entry"));
if (elementMenu != null && elementMenu.hasAttr("data-z")
&& elementMenu.attr("data-z").equals("user-managed")) {
menuEntry.setUserManaged(true);
menuEntry.setCodeManaged(elementMenu.outerHtml());
}
}
ctx.addExtraParameter("userManagedComponents", mergeStructure(loadExistingDoc));
ctx.addExtraParameter("menuEntries", menuEntries);
Document newDoc = process(templateName, ctx);
return newDoc;
}
代码示例来源:origin: spring-projects/spring-roo
@Override
public Document mergeListDeleteModalView(String templateName, Document loadExistingDoc,
ViewContext<ThymeleafMetadata> ctx, EntityItem entity, List<FieldItem> fields) {
// Get field code if data-z attribute value is equals to user-managed
Element elementField =
loadExistingDoc.getElementById(entity.getEntityItemId().concat("-table"));
if (elementField != null && elementField.hasAttr("data-z")
&& elementField.attr("data-z").equals("user-managed")) {
entity.setUserManaged(true);
entity.setCodeManaged(elementField.outerHtml());
}
ctx.addExtraParameter("userManagedComponents", mergeStructure(loadExistingDoc));
ctx.addExtraParameter("entity", entity);
ctx.addExtraParameter("fields", fields);
Document newDoc = process(templateName, ctx);
return newDoc;
}
代码示例来源:origin: spring-projects/spring-roo
@Override
public Document mergeListDeleteModalDetailView(String templateName, Document loadExistingDoc,
ViewContext<ThymeleafMetadata> ctx, EntityItem entity, List<FieldItem> fields) {
// Get field code if data-z attribute value is equals to user-managed
Element elementField =
loadExistingDoc.getElementById(entity.getEntityItemId().concat("-table"));
if (elementField != null && elementField.hasAttr("data-z")
&& elementField.attr("data-z").equals("user-managed")) {
entity.setUserManaged(true);
entity.setCodeManaged(elementField.outerHtml());
}
ctx.addExtraParameter("userManagedComponents", mergeStructure(loadExistingDoc));
ctx.addExtraParameter("entity", entity);
ctx.addExtraParameter("fields", fields);
Document newDoc = process(templateName, ctx);
return newDoc;
}
代码示例来源:origin: spring-projects/spring-roo
@Override
public Document mergeListDeleteModalBatchView(String templateName, Document loadExistingDoc,
ViewContext<ThymeleafMetadata> ctx, EntityItem entity, List<FieldItem> fields) {
// Get field code if data-z attribute value is equals to user-managed
Element elementField =
loadExistingDoc.getElementById(entity.getEntityItemId().concat("-table"));
if (elementField != null && elementField.hasAttr("data-z")
&& elementField.attr("data-z").equals("user-managed")) {
entity.setUserManaged(true);
entity.setCodeManaged(elementField.outerHtml());
}
ctx.addExtraParameter("userManagedComponents", mergeStructure(loadExistingDoc));
ctx.addExtraParameter("entity", entity);
ctx.addExtraParameter("fields", fields);
Document newDoc = process(templateName, ctx);
return newDoc;
}
代码示例来源:origin: spring-projects/spring-roo
@Override
public Document mergeListDeleteModalBatchDetailView(String templateName,
Document loadExistingDoc, ViewContext<ThymeleafMetadata> ctx, EntityItem entity,
List<FieldItem> fields) {
// Get field code if data-z attribute value is equals to user-managed
Element elementField =
loadExistingDoc.getElementById(entity.getEntityItemId().concat("-table"));
if (elementField != null && elementField.hasAttr("data-z")
&& elementField.attr("data-z").equals("user-managed")) {
entity.setUserManaged(true);
entity.setCodeManaged(elementField.outerHtml());
}
ctx.addExtraParameter("userManagedComponents", mergeStructure(loadExistingDoc));
ctx.addExtraParameter("entity", entity);
ctx.addExtraParameter("fields", fields);
Document newDoc = process(templateName, ctx);
return newDoc;
}
代码示例来源:origin: spring-projects/spring-roo
loadExistingDoc.getElementById(entity.getEntityItemId().concat("-table"));
if (elementField != null && elementField.hasAttr("data-z")
&& elementField.attr("data-z").equals("user-managed")) {
loadExistingDoc.getElementById(detail.getEntityItemId().concat("-table"));
if (elementDetail != null && elementDetail.hasAttr("data-z")
&& elementDetail.attr("data-z").equals("user-managed")) {
loadExistingDoc.getElementById(detail.getEntityItemId().concat("-table-tab"));
if (elementTabCodeDetailField != null && elementTabCodeDetailField.hasAttr("data-z")
&& elementTabCodeDetailField.attr("data-z").equals("user-managed")) {
代码示例来源:origin: spring-projects/spring-roo
@Override
public Document merge(String templateName, Document loadExistingDoc,
ViewContext<ThymeleafMetadata> ctx, List<FieldItem> fields) {
for (FieldItem field : fields) {
// Get field code if data-z attribute value is equals to
// user-managed
Element elementField = loadExistingDoc.getElementById(field.getFieldId());
if (elementField != null && elementField.hasAttr("data-z")
&& elementField.attr("data-z").equals("user-managed")) {
field.setUserManaged(true);
field.setCodeManaged(elementField.outerHtml());
}
}
ctx.addExtraParameter("userManagedComponents", mergeStructure(loadExistingDoc));
ctx.addExtraParameter("fields", fields);
Document newDoc = process(templateName, ctx);
return newDoc;
}
代码示例来源:origin: spring-projects/spring-roo
private Document mergeDetailsCompositionView(String templateName, Document loadExistingDoc,
ViewContext ctx, EntityItem entityItem, DetailEntityItem detail, List<FieldItem> fields) {
for (FieldItem field : fields) {
// Get field code if data-z attribute value is equals to
// user-managed
Element elementField = loadExistingDoc.getElementById(field.getFieldId());
if (elementField != null && elementField.hasAttr("data-z")
&& elementField.attr("data-z").equals("user-managed")) {
field.setUserManaged(true);
field.setCodeManaged(elementField.outerHtml());
} else {
field.setUserManaged(false);
field.setCodeManaged("");
}
}
ctx.addExtraParameter("fields", fields);
ctx.addExtraParameter("userManagedComponents", mergeStructure(loadExistingDoc));
return process(templateName, ctx);
}
代码示例来源:origin: asciidoctor/asciidoctorj
@Test
public void a_postprocessor_should_be_executed_after_document_is_rendered() throws IOException {
JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry();
javaExtensionRegistry.postprocessor(CustomFooterPostProcessor.class);
Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html"))
.safe(SafeMode.UNSAFE).get();
asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options);
File renderedFile = new File(testFolder.getRoot(), "rendersample.html");
org.jsoup.nodes.Document doc = Jsoup.parse(renderedFile, "UTF-8");
Element footer = doc.getElementById("footer-text");
assertThat(footer.text(), containsString("Copyright Acme, Inc."));
}
代码示例来源:origin: asciidoctor/asciidoctorj
@Test
public void no_footer_attribute_should_not_show_footer_info() throws IOException {
Attributes attributes = attributes().noFooter(true).get();
Options options = options().inPlace(false).safe(SafeMode.UNSAFE)
.toDir(testFolder.getRoot()).attributes(attributes).get();
asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options);
Document doc = Jsoup.parse(new File(testFolder.getRoot(), "rendersample.html"), "UTF-8");
assertThat(doc.getElementById("footer"), is(nullValue()));
}
内容来源于网络,如有侵权,请联系作者删除!