本文整理了Java中org.jsoup.nodes.Element.dataNodes()
方法的一些代码示例,展示了Element.dataNodes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.dataNodes()
方法的具体详情如下:
包路径:org.jsoup.nodes.Element
类名称:Element
方法名:dataNodes
[英]Get this element's child data nodes. The list is unmodifiable but the data nodes may be manipulated.
This is effectively a filter on #childNodes() to get Data nodes.
[中]获取此元素的子数据节点。该列表不可修改,但数据节点可能会被操纵。
这实际上是对#childNodes()的一个过滤器,用于获取数据节点。
代码示例来源:origin: decaywood/XueQiuSuperSpider
private JsonNode parseHtmlToJsonNode(String content) throws IOException {
Document doc = Jsoup.parse(content);
String indexer1 = "follows=";
String indexer2 = ";seajs.use";
StringBuilder builder = new StringBuilder(
doc.getElementsByTag("script")
.get(15)
.dataNodes()
.get(0)
.attr("data"));
int index = builder.indexOf(indexer1);
builder.delete(0, index + indexer1.length());
index = builder.indexOf(indexer2);
builder.delete(index, builder.length());
return mapper.readTree(builder.toString());
}
}
代码示例来源:origin: stackoverflow.com
Document doc =Jsoup.connect("http://stackoverflow.com/questions/16780517/java-obtain-text-within-script-tag-using-jsoup").timeout(10000).get();
Elements scriptElements = doc.getElementsByTag("script");
for (Element element :scriptElements ){
for (DataNode node : element.dataNodes()) {
System.out.println(node.getWholeData());
}
System.out.println("-------------------");
}
代码示例来源:origin: astamuse/asta4d
public List<DataNode> dataNodes() {
return originElement.dataNodes();
}
代码示例来源:origin: stackoverflow.com
for (Element tag : scriptTags){
for (DataNode node : tag.dataNodes()) {
System.out.println(node.getWholeData());
}
}
代码示例来源:origin: stackoverflow.com
final String newFontInfo = "@font-face { \n"
+ "font-family: 'MyFont';\n"
+ "src: url('file:///android_asset/Custom-Font.otf')\n" + "}\n";
Elements styles = doc.select("style");
for (Element style : styles) {
for (DataNode data : style.dataNodes()) {
String dataTxt = data.getWholeData();
if (dataTxt.contains("font-family")) {
final String newData = dataTxt.replaceAll("font-family:\\s*'[^']*'","font-family: 'MyFont'");
data.setWholeData(newFontInfo + newData);
}
}
}
代码示例来源:origin: stackoverflow.com
// Set Current Directory
String currentDir = new File("").getAbsolutePath();
// Open text file
FileWriter writer = new FileWriter(currentDir + "/BerkeleyGroupScrape.txt");
// Connect to HTML page and get content
Document doc = Jsoup.connect("http://www.berkeleygroup.co.uk/search-results").timeout(10*1000).get();
Elements scriptTags = doc.getElementsByTag("script");
int i = 0;
for (Element tag : scriptTags){
if (i > 2) { continue; }
for (DataNode node : tag.dataNodes()) {
System.out.println(node.getWholeData());
writer.append(node.getWholeData());
i++;
}
}
// Close text file
writer.flush();
writer.close();
代码示例来源:origin: padeoe/nju-lib-downloader
private void getBookPara(String url) throws BookDLException {
String html = getBookViewPageHtml(url);
Document doc = Jsoup.parse(html);
Element infoNode = doc.getElementsByTag("script").last();
pageNumberMap = new HashMap<>();
int epage = 0;
if (infoNode.dataNodes().size() > 0) {
String paraJs = infoNode.dataNodes().get(0).getWholeData();
Pattern pattern = Pattern.compile("var str='(.*)';.*epage = (\\d+);.*pages :\\[\\[1,(\\d+)\\],\\[1,(\\d+)\\],\\[1,(\\d+)\\]," +
"\\[1,(\\d+)\\], \\[1,(\\d+)\\], \\[spage, epage\\], \\[1,(\\d+)\\], \\[1,(\\d+)\\]\\],.*", Pattern.DOTALL);
Matcher matcher = pattern.matcher(paraJs);
if (matcher.find()) {
urlPrefix = matcher.group(1);
pageNumberMap.put(pageTypes[5], Integer.parseInt(matcher.group(2)));
pageNumberMap.put(pageTypes[0], Integer.parseInt(matcher.group(3)));
pageNumberMap.put(pageTypes[1], Integer.parseInt(matcher.group(4)));
pageNumberMap.put(pageTypes[2], Integer.parseInt(matcher.group(5)));
pageNumberMap.put(pageTypes[3], Integer.parseInt(matcher.group(6)));
pageNumberMap.put(pageTypes[4], Integer.parseInt(matcher.group(7)));
pageNumberMap.put(pageTypes[6], Integer.parseInt(matcher.group(8)));
pageNumberMap.put(pageTypes[7], Integer.parseInt(matcher.group(9)));
} else {
throw new BookDLException(book);
}
} else {
System.out.println(book.getId() + " 参数获取失败");
throw new BookDLException(book);
}
}
代码示例来源:origin: com.sangupta/jerry-web
for (DataNode dn : element.dataNodes()) {
sourceFiles.add(dn.getWholeData());
代码示例来源:origin: belerweb/social-sdk
Elements scripts = doc.select("script");
for (Element el : scripts) {
for (DataNode node : el.dataNodes()) {
String script = node.getWholeData().trim();
if (script.startsWith("var goListData")) {
代码示例来源:origin: belerweb/social-sdk
boolean status = false;
for (Element el : scripts) {
for (DataNode node : el.dataNodes()) {
String script = node.getWholeData().trim();
if (script.startsWith("var urlHead")) {
内容来源于网络,如有侵权,请联系作者删除!