当前位置:网站首页>2021.8.6 notes jsoup
2021.8.6 notes jsoup
2022-07-27 18:33:00 【It's food, not shellfish】
jsoup object


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.IOException;
import java.net.URL;
public class xmlJsoupPra {
public static void main(String[] args) throws IOException {
/** * 1.parse( file ( Need to path), Encoding mode ) */
String path = xmlJsoupPra.class.getClassLoader().getResource("student.xml").getPath();
Document document = Jsoup.parse(new File(path), "utf-8");
Elements eles = document.getElementsByTag("name");
Element element = eles.get(0);
String text = element.text();
System.out.println(text);
/** * 2.String */
String str = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" +
"<students>\n" +
" <studnt number=\"1001\">\n" +
" <name>zhangsan</name>\n" +
" <age>18</age>\n" +
" <grender>male</grender>\n" +
" </studnt>\n" +
" <studnt number=\"1002\">\n" +
" <name>lisi</name>\n" +
" <age>15</age>\n" +
" <grender>female</grender>\n" +
" </studnt>\n" +
"</students>";
Document parse1 = Jsoup.parse(str);
System.out.println(parse1);
/** * 3.url */
URL url = new URL("https://www.baidu.com");
Document parse2 = Jsoup.parse(url, 10000);
System.out.println(parse2);
}
}
Document object
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.IOException;
public class DocumentObj {
public static void main(String[] args) throws IOException {
String path = DocumentObj.class.getClassLoader().getResource("student.xml").getPath();
Document docu1 = Jsoup.parse(new File(path), "utf-8");
Elements ele1 = docu1.getElementsByAttribute("number");
Element element = ele1.get(0);
System.out.println(element);
Elements ele2 = docu1.getElementsByAttributeValue("number", "1001");
System.out.println(ele2);
Element ele3 = docu1.getElementById("i5");
System.out.println(ele3);
}
}
Element object
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.IOException;
public class ElementObj {
public static void main(String[] args) throws IOException {
String path = ElementObj.class.getClassLoader().getResource("student.xml").getPath();
Document docu1 = Jsoup.parse(new File(path), "utf-8");
Element ele1 = docu1.getElementsByTag("student").get(0);
Elements ele2 = ele1.getElementsByTag("name");
System.out.println(ele2);
String num = ele1.attr("number");
System.out.println(num);
Element age = ele1.getElementsByTag("age").get(0);
String text = age.text();
System.out.println(text);
String htmlAge = age.html();
System.out.println(htmlAge);
}
}
Query by selector
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.IOException;
public class SelectObj {
public static void main(String[] args) throws IOException {
String path = SelectObj.class.getClassLoader().getResource("student.xml").getPath();
Document docu = Jsoup.parse(new File(path), "utf-8");
Elements nameEle = docu.select("name");
System.out.println(nameEle);
Elements IdEle= docu.select("#i5");
System.out.println(IdEle);
Elements newEle = docu.select("name[id=\"i5\"]");
System.out.println(newEle);
Elements newEle2 = docu.select("student[number=\"1001\"] age"); //> If yes, it is a level-1 sub tag
System.out.println(newEle2);
}
}
边栏推荐
- Dynamic linked list 4 one-way circular linked list (loopsingle Implementation)
- 微信小程序获取手机号
- 2021.7.13 note sub query
- RSA encryption and decryption (compatible with wechat applet environment)
- [MIT 6.S081] Lab 4: traps
- Chained storage structure of dynamic linked list 3 queue (linkedqueue Implementation)
- 深度学习:GAT
- LootCode动态数组练习(724,118,766)
- @Considerations for query of convert annotation in JPA
- Zhanrui fresh seedlings: enable full scene applications, and massive data needs the integration of AI and IOT
猜你喜欢

Deep learning: GCN diagram classification case

Common commands of database 2

深度学习-论文阅读:动作结构性图卷积网络AS-GCN

1. OpenCV image basic operation

2021.7.31 note view

Let's move forward together, the 10th anniversary of Google play!

2021.7.22 note constraints

Deep recognition: thesis reading_ 2s-agcn cvpr2019 (two stream adaptive graph convolution network based on skeleton action recognition)

2021.7.19 notes DML
![[MIT 6.S081] Lab 11: networking](/img/9d/cca59a662412f3c3c57c26c5987a24.png)
[MIT 6.S081] Lab 11: networking
随机推荐
Marvell公布旗下Arm服务器芯片路线图,下一代性能将比ThunderX2高两倍
[MIT 6.S081] Lab 4: traps
Deep recognition: thesis reading_ 2s-agcn cvpr2019 (two stream adaptive graph convolution network based on skeleton action recognition)
rsa加解密(兼容微信小程序环境)
二叉树概念
Deep learning - paper reading: action structural graph convolution network as-gcn
Three consecutive high-frequency interview questions of redis online celebrity: cache penetration? Cache breakdown? Cache avalanche?
An analysis of CPU explosion of a smart logistics WCS system in.Net
2021.8.1笔记 DBA
Let's move forward together, the 10th anniversary of Google play!
Hackers use lasers to attack, and voice assistants can be activated from a distance of 100 meters
Please ask the great God a question, flinkcdc, the datetime field in synchronous MySQL will become a timestamp. Has anyone ever encountered it
2021.7.28笔记 事务
Guoju spent $1.8 billion to acquire its competitor KEMET, and the transaction may be completed in the second half of next year
NVIDIA released the world's smallest edge AI supercomputing: 21tops computing power, power consumption is only 10W!
2021.7.13笔记 子查询
[MIT 6.S081] Lab 3: page tables
MySQL four locks
Jrs-303 usage
软件安装相关