当前位置:网站首页>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);
}
}
边栏推荐
- [MIT 6.S081] Lec 6: Isolation & system call entry/exit 笔记
- 微信小程序获取openId, sessionKey, unionId
- Intel releases a new generation of movidius Vpu: 10 times higher performance and 30W power consumption
- The end of another era!
- [mit 6.s081] LEC 6: isolation & system call entry/exit notes
- [mit 6.s081] LEC 1: introduction and examples notes
- Jianan Yunzhi has completed the pre roadshow and is expected to land on NASDAQ on November 20
- 江苏华存首发PCIe 5.0 SSD主控:台积电12nm工艺,2020年量产
- [MIT 6.S081] Lab 5: xv6 lazy page allocation
- 2021.7.13 note sub query
猜你喜欢
![[MIT 6.S081] Lec 1: Introduction and examples 笔记](/img/5d/2fc4bde8eebbb22605d314b5292e05.png)
[MIT 6.S081] Lec 1: Introduction and examples 笔记
![[MIT 6.S081] Lab 5: xv6 lazy page allocation](/img/f6/8b619412bc6ba425d0f04629917e80.png)
[MIT 6.S081] Lab 5: xv6 lazy page allocation

How do corporate giants such as Schneider Electric and L'Oreal make open innovation? Uncover secrets of demo World Innovation Summit

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

2021.7.12 internal and external connection of notes

深度识别:论文阅读_2S-AGCN CVPR2019(基于骨架的动作识别的两流自适应图卷积网络)

2021.7.12笔记 内外连接

文件路径读取

Binary tree concept

multi-table query
随机推荐
An analysis of CPU explosion of a smart logistics WCS system in.Net
Solution to invalid SQL Server connection to server
Meituan Er Mian: why does redis have sentinels?
rsa加解密(兼容微信小程序环境)
[mit 6.s081] LEC 3: OS organization and system calls notes
Here comes the first 5g SOC of MediaTek! A77+g77+apu3.0, officially released on November 26!
[MIT 6.S081] Lab 4: traps
Zhanrui fresh seedlings: enable full scene applications, and massive data needs the integration of AI and IOT
Software installation related
发布自己的npm组件库
[MIT 6.S081] Lab 3: page tables
File path read
Deep learning - paper reading: action structural graph convolution network as-gcn
Super practical! After reading the kubernetes study notes hidden by Alibaba P9, call NB directly
力压谷歌、英伟达!阿里含光800芯片再获权威测试世界第一
LootCode动态数组练习(724,118,766)
Deep learning: a survey of behavior recognition
Graphical interface programming
Chained storage structure of dynamic linked list 3 queue (linkedqueue Implementation)
2. Change color space and color detection