本文整理汇总了Java中org.jsoup.nodes.Element.outerHtml方法的典型用法代码示例。如果您正苦于以下问题:Java Element.outerHtml方法的具体用法?Java Element.outerHtml怎么用?Java Element.outerHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.nodes.Element
的用法示例。
在下文中一共展示了Element.outerHtml方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseAlbumData
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public static Map<String, Object> parseAlbumData(String albumURL) throws Exception
{
Map<String, Object> albumMap = new HashMap<String, Object>();
Elements scriptTags = HttpUtil.getScriptList(albumURL);
for(Element element : scriptTags)
{
String text = element.outerHtml();
if(StringUtils.containsIgnoreCase(text, "var TralbumData"))
{
String albumData = extractJson(text, "var TralbumData =", "};",false) + "};";
if(StringUtils.isNotBlank(albumData))
{
Map<String, String> jsonMap = getJsonMap(albumData);
JsonObject albumJsonObject = new JsonParser().parse(jsonMap.get("current")).getAsJsonObject();
List<JsonObject> trackList = getTrackInfo(jsonMap.get("trackinfo"));
albumMap.put("albumMetadata", albumJsonObject);
albumMap.put("trackMetadata", trackList);
return albumMap;
}
}
}
return null;
}
示例2: extractDataWithJsoup
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public void extractDataWithJsoup(String href){
Document doc = null;
try {
doc = Jsoup.connect(href).timeout(10*1000).userAgent("Mozilla").ignoreHttpErrors(true).get();
} catch (IOException e) {
//Your exception handling here
}
if(doc != null){
String title = doc.title();
String text = doc.body().text();
Elements links = doc.select("a[href]");
for (Element link : links) {
String linkHref = link.attr("href");
String linkText = link.text();
String linkOuterHtml = link.outerHtml();
String linkInnerHtml = link.html();
}
}
}
示例3: parseForContent
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public static String parseForContent(String key, Element seItemBody) {
String content = seItemBody.outerHtml();
// check if key is found and remove everything in front
int keyOccurrence = content.toLowerCase().indexOf(key);
if (keyOccurrence == -1) {
return "";
} else {
content = content.substring(keyOccurrence + key.length());
}
// check if line break is found and remove everything in front
// assumption: content is right after the key and on new line
int firstLineBreak = content.indexOf("<br>");
if (firstLineBreak == -1) {
return "";
} else {
content = content.substring(firstLineBreak + 4);
}
content = content.replaceAll("\r", "");
content = content.replaceAll("\n", "");
// only read until the next line break
Pattern patternLineBreak = Pattern.compile("(.+?)<br>.*");
Matcher matcherLineBreak = patternLineBreak.matcher(content);
// if no line break tag is found just read until the next html tag occurs
Pattern patternTag = Pattern.compile("(.+?)<.*>.*");
Matcher matcherTag = patternTag.matcher(content);
if (matcherLineBreak.find()) {
content = matcherLineBreak.group(1);
} else if (matcherTag.find()) {
content = matcherTag.group(1);
} else {
LOG.debug("No end html tag for key '{}' in [{}] parsed from [{}]", key, content, seItemBody.outerHtml());
}
content = content.trim();
return content;
}
示例4: getValue
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private String getValue(Element element) {
if (attrName == null) {
return element.outerHtml();
} else if ("innerHtml".equalsIgnoreCase(attrName)) {
return element.html();
} else if ("text".equalsIgnoreCase(attrName)) {
return getText(element);
} else if ("allText".equalsIgnoreCase(attrName)) {
return element.text();
} else {
return element.attr(attrName);
}
}
示例5: getValue
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private <U> String getValue(Element node, Class<U> clazz) {
if (node == null) {
return defValue;
}
String value;
switch (attribute) {
case "":
value = node.text();
break;
case "html":
case "innerHtml":
value = node.html();
break;
case "outerHtml":
value = node.outerHtml();
break;
default:
value = node.attr(attribute);
break;
}
if (!clazz.equals(Date.class)
&& !clazz.equals(BigDecimal.class)
&& !format.equals(Selector.NO_VALUE)) {
Pattern pattern = Pattern.compile(format);
Matcher matcher = pattern.matcher(value);
boolean found = matcher.find();
if (found) {
value = matcher.group(1);
if (value.isEmpty()) {
value = defValue;
}
}
}
return value;
}
示例6: getValue
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private String getValue(Element element, String attrName) {
if (attrName == null) {
return element.outerHtml();
} else if ("innerHtml".equalsIgnoreCase(attrName)) {
return element.html();
} else if ("text".equalsIgnoreCase(attrName)) {
return getText(element);
} else if ("allText".equalsIgnoreCase(attrName)) {
return element.text();
} else {
return element.attr(attrName);
}
}