一、简介

该类是位于select包下,直接继承自Object,所有实现的接口有Cloneable, Iterable, Collection, List

类声明:public class Elements extends Object implements List, Cloneable

可以使用Element.select(String) 方法去得到Elements 对象。

二、构造方法

1、public Elements() 默认构造方法
2、public Elements(int initialCapacity) 指定一个初始容量创建一个Elements对象。

3、public Elements(Collection elements) 使用已知元素集创建一个Elements对象。

4、public Elements(List elements) 使用已知元素的List集合创建一个Elements对象。

5、public Elements(Element… elements) 使用已知元素的可变参数列表创建一个Elements对象。

三、方法详细

1、public Elements clone() 克隆

2、public String attr(String attributeKey) 根据键得到第一个匹配的元素(匹配即为有这个属性)。

3、public boolean hasAttr(String attributeKey) 元素集中存在任何一个元素匹配(有这属性)则返回true。

4、public Elements attr(String attributeKey, String attributeValue) 将 所有匹配attributeKey键的元素的值设置为attributeValue。

5、public Elements removeAttr(String attributeKey) 移除元素集中任何一个匹配的元素

6、public Elements addClass(String className) 将className增加到每一个匹配的元素的class属性上。

7、public Elements removeClass(String className) 从每一个匹配的元素上移除该className

8、public Elements toggleClass(String className) 对每一个匹配的元素的class属性上进行反转。(有则移除,没有则新增)。

9、public boolean hasClass(String className) 检测是否有任何一个匹配的元素在class属性有给定的className值。

10、public String val() 得到第一个匹配元素的表单的值。

11、public Elements val(String value) 对每一个匹配的元素设置表单值。

12、public String text() 得到所有匹配元素文本的综合。该方法在某些情况下会得到重复数据。

13、public boolean hasText() 检测是否有文本内容

14、public String html() 得到所有匹配元素的内部html的综合。

15、public String outerHtml() 得到所有匹配元素的外部html的综合。

16、public String toString() 得到所有匹配元素的外部html的综合。

17、public Elements tagName(String tagName) 更新每个匹配元素的tag name. 如想把每个变成,可以这样:doc.select(“i”).tagName(“em”);

18、public Elements html(String html) 设置每个匹配元素的内部html。

19、public Elements prepend(String html) 将指定html增加到每个匹配元素的内部html开头。

20、public Elements append(String html) 将指定html增加到每个匹配元素的内部html末尾。

21、public Elements before(String html) 在每个匹配元素的外部html前面插入指定html。

22、public Elements after(String html) 在每个匹配元素的外部html后面插入指定html。

23、public Elements wrap(String html) 用指定html包装每个匹配的元素。

例如,对于这个html:

This is Jsoup

,执行这个包装:doc.select(“b”).wrap(" ")后就变成:

This is jsoup

24、public Elements unwrap() 移除匹配的元素但保留他们的内容。示例:

One Two

执行 doc.select(“font”).unwrap() 变成:

One Two

25、public Elements empty() 清空每个匹配元素的内容。示例:

Hello there

now

执行doc.select(“p”).empty() 变成

26、public Elements remove() 从DOM树中移除匹配的元素。示例:

Hello

there

执行doc.select(“p”).remove()后 变成

27、public Elements select(String query) 根据query选择器查询匹配的元素集。

28、public Elements not(String query) 移除匹配选择器的元素集 返回过滤后的元素集。

29、public Elements eq(int index) 根据index得到匹配的元素

30、public boolean is(String query) 检测是否有一个元素匹配给定的选择器。

31、public Elements parents() 得到匹配元素集的所有父类元素和祖先元素集

32、public Element first() 得到第一个匹配的元素

33、public Element last() 得到最后一个匹配的元素

34、public Elements traverse(NodeVisitor nodeVisitor) 对被查询的元素执行一次深度优先的遍历。

35、public int size() 元素集的长度。

36、public boolean isEmpty() 检测是否为空

37、public boolean contains(Object o) 检测是否包含指定对象

38、public Iterator iterator() 得到迭代器对象

39、public Object[] toArray() 将元素集转换为数组

40、public T[] toArray(T[] a)

41、public boolean add(Element element) 新增元素

42、public boolean remove(Object o) 移除指定元素

43、public boolean containsAll(Collection<?> c) 参照java中的List或Collection用法.

44、public boolean addAll(Collection<? extends Element> c) 参照java中的List或Collection用法.

45、public boolean addAll(int index, Collection<? extends Element> c) 参照java中的List或Collection用法.

46、public boolean removeAll(Collection<?> c) 参照java中的List或Collection用法.

47、public boolean retainAll(Collection<?> c) 参照java中的List或Collection用法.

48、public void clear() 清空元素集

49、public Element get(int index) 根据索引得到指定元素

50、public Element set(int index, Element element) 根据索引设置指定元素

51、public void add(int index, Element element) 在指定位置增加元素

52、public Element remove(int index) 移除指定位置的元素

53、public int indexOf(Object o) 得到指定元素的索引(第一次出现的位置)

54、public int lastIndexOf(Object o) 得到指定元素最后一次出现的位置。

55、public ListIterator listIterator() 具体参照List

56、public ListIterator listIterator(int index) 具体参照List

57、public List subList(int fromIndex, int toIndex) 根据起始点得到子集

原文:https://blog.csdn.net/u010682330/article/details/81805473

jsoup的Elements类相关推荐

  1. java中elements类_jsoup的elements类

    jsoup的Elements类 一.简介 该类是位于select包下,直接继承自Object,所有实现的接口有Cloneable, Iterable, Collection, List 类声明:pub ...

  2. Jsoup 处理html 元素(Elements类种各个方法的使用说明)

    static void main(String[] args) { // 根据全国各个高校的地址,获取视频中相应列表的URL和要抓取的值         Document document = nul ...

  3. jsoup的Elements Api 使用

    public static void main(String[] args) { // 根据全国各个高校的地址,获取视频中相应列表的URL和要抓取的值Document document = null; ...

  4. jsoup的Node类

    2019独角兽企业重金招聘Python工程师标准>>> 一.简介 Node类直接继承Object,实现了Cloneable接口,它是一个抽象类,类声明:public abstract ...

  5. jsoup 的基本使用以及API内容

    Jsoup 获取 Document 的三种方法: 1. 读取取字符串的方式获取 Document,代码如下所示: @Test //获取完整的字符串内容 public void test01() {St ...

  6. [XML-Jsoup]Jsoup_对象的使用(Jsoup工具类,Document,Elements,Element,Node)

    对象的使用: 1. Jsoup:工具类,可以解析html或xml文档,返回Document* parse:解析html或xml文档,返回Document* parse​(File in, String ...

  7. Jsoup的网页工具类

    如果有相关问题,可以一起研究下 引入相关依赖 <!-- Html工具 --> <dependency><groupId>org.jsoup</groupId& ...

  8. Java爬虫之利用Jsoup+HttpClient爬取类叔叔不约匿名聊天网站的图片,未果——后爬取某网站美女图片案例

    博主最近学了一点爬虫的知识,闲着无聊,秉承学以致用的理念,于是突然想到何不挑战一下,爬取一些叔叔不约网站的图片,来巩固一下所学知识(#滑稽).说干就干,打开eclipse或idea,创建maven工程 ...

  9. WebDriver 登陆 Jsoup抓取内容

    2019独角兽企业重金招聘Python工程师标准>>> 1. 环境 pom: <project xmlns="http://maven.apache.org/POM/ ...

最新文章

  1. Python中list和set的区别
  2. [CQOI2015]任务查询系统
  3. 解决在已办任务菜单中都会抛出异常,由于definitionId=undefined导致的问题
  4. 虚拟化之vmware-vsphere (web) client
  5. Linux下tomcat的服务器自启动配置
  6. Tensorflow卷积神经网络识别MINST手写数字
  7. LeetCode 第 3 题(Longest Substring Without Repeating Characters)
  8. Android服务注册完整过程源码分析
  9. CentOS中恢复rm命令误删文件
  10. Python OrderedDict
  11. 最近 搞定这5篇 java相关
  12. LA 3268 号码簿分组(最大流+二分)
  13. Html5下载功能实现
  14. html控制萤石云摄像头转动,怎么控制云台转动 ?
  15. # Android12 wifi和4G同时使用
  16. 多元函数偏导数连续、存在与可微的关系
  17. ORACLE的jdbc驱动包版本
  18. pca 累积方差贡献率公式_SPSS主成分分析时,是不是得到的方差百分比就是贡献率,累计百分比就是累计贡献率??...
  19. 欧莱雅迎来入华25周年;万代南梦宫集团将启用新logo | 美通企业日报
  20. 2021-2022年小学期 程序设计开发实践 随堂笔记

热门文章

  1. CoreAnimation编程指南(八)事务
  2. 交叉线和直通线各自用于什么场合?为什么?_【小麓讲堂】偏振光与LCD、OLED、3D、AR到底有什么关系?...
  3. oracle 31640,导数据时ora-31640报错
  4. unity自动生成敌人_Unity 3D做2D坦克大战--敌人自动攻击AI编写
  5. wordcount java分析_JavaWordCount
  6. 静态网页托管_视频教程:如何在IPFS上托管网站!
  7. 【LeetCode笔记】35. 搜索插入位置(Java、二分法)
  8. python识别人脸多种属性_深度学习人脸识别仅9行python代码实现?同时高效处理100张相片?...
  9. ubuntu tomcat上传目录权限_等了 3 年,Ubuntu Studio 终于有权限上传更新包
  10. bcp out 带列名导出_从零开始学习 MySQL 系列索引、视图、导入和导出