jsoup的Elements类

一、简介

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

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

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

二、构造方法

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

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

4、public Elements(List<Element> 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.   如想把每个<i>变成<em>,可以这样: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:<p><b>This</b> is <b>Jsoup</b></p>,执行这个包装:doc.select("b").wrap("<i></i>")后就变成:<p><i><b>This</b></i> is <i><b>jsoup</b></i></p>

24、public Elements unwrap()   移除匹配的元素但保留他们的内容。示例:<div><font>One</font> <font><a href="/">Two</a></font></div>   执行 doc.select("font").unwrap()   变成:<div>One <a href="/">Two</a></div>
25、public Elements empty()  清空每个匹配元素的内容。示例:<div><p>Hello <b>there</b></p> <p>now</p></div>  执行doc.select("p").empty()  变成<div><p></p> <p></p></div>

26、public Elements remove()  从DOM树中移除匹配的元素。示例:<div><p>Hello</p> <p>there</p> <img /></div>   执行doc.select("p").remove()后 变成<div> <img /></div>

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<Element> iterator()   得到迭代器对象

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

40、public <T> 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<Element> listIterator() 具体参照List<Element>

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

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

jsoup的elements类的更多相关文章

  1. jsoup的Element类

    一.简介 该类是Node的直接子类,同样实现了可克隆接口.类声明:public class Element extends Node 它表示由一个标签名,多个属性和子节点组成的html元素.从这个元素 ...

  2. jsoup的Document类

    一.简介 Document是一个装载html的文档类,它是jsoup一个非常重要的类.类声明:public class Document extends Element .Document是Node间 ...

  3. jsoup的Node类

    一.简介 Node类直接继承Object,实现了Cloneable接口,它是一个抽象类,类声明:public abstract class Node extends Object implements ...

  4. jsoup获取文档类示例

    import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsou ...

  5. Jsoup使用随记

    这段时间工作比较空闲,在网上找资料学习的时候看到数据抓取这一块,来了兴趣 用jsoup实现数据抓取着实方便,唯一美中不足的是官方API是英文版的,对我这样英语水平不好的程序员来说着实困扰,只能一点点的 ...

  6. jsoup

    jsoup 相关知识链接:http://blog.csdn.net/column/details/jsoup.htm http://www.jb51.net/article/43485.htm htt ...

  7. jsoup简单的爬取网页数据

    /** * Project Name:JavaTest * File Name:BankOfChinaExchangeRate.java * Package Name:com.lee.javatest ...

  8. jsoup解析HTML及简单实例

    jsoup 中文参考文献    http://www.open-open.com/jsoup/ 本文将利用jsoup,简单实现网络抓取的功能,并给出一个小实例,该实例效果为:获取作者本人在博客园写的所 ...

  9. HttpClient + Jsoup模拟登录教务处并获取课表

    1.概述 最近想做一个校园助手类的APP,由于第一次做,所以打算先把每个功能单独实现,防止乱了阵脚.利用教务处登录获取课表和成绩等是一个基本功能,所以以获取课表为例实现了这个功能.完整代码点这里,尝试 ...

随机推荐

  1. [开发笔记]-Windows Service服务相关注意事项

    注意一:报错:“本地计算机上的 *** 服务启动后停止.某些服务在未由其他服务或程序使用时将自动停止.” 该问题主要的原因是 Service服务程序中有错误. 遇到这个问题时,无论是重新安装服务,还是 ...

  2. 查看UI调试界面利器 revealapp

    官网 http://revealapp.com 做iOS的开发,UI是非常非常重要的一环.调试时我们一般用模拟器,提交前用真机做测试.用模拟器来调试UI效果虽然快捷方便,但有时仍然希望有更强大的工具来 ...

  3. 框架之 spring

    spring有两大特性,其一为ioc,其二为aop 1.ioc的理解 ioc为依赖注入,他的好处就是把创建对象的权利交给spring去管理,这样的好处是 将应用程序中的对象解耦,传统的方式程序中的对象 ...

  4. declare 关键字在Oracle中的应用。

    一般用在trigger或匿名存储过程中使用.如 declare a number;begina:=1;end;

  5. JS 中的五个假值

    1."", undefined, null, 0, NaN 除了这五个假值以外,其他所有值转布尔类型都是true.还有一个特殊的false.

  6. Matlab单一变量曲线拟合-cftool

    2.启动曲线拟合工具箱>cftool 3.进入曲线拟合工具箱界面“Curve Fitting tool”(1)点击“Data”按钮,弹出“Data”窗口:(2)利用X data和Y data的下 ...

  7. hdu 2053

    Ps:找规律题....凡是平方数都是开...WA了一次..数组给的太小?...后来给到3000..就AC了 代码: #include "stdio.h"long long dp[3 ...

  8. 2016 - 1- 19 利用多线程优化从网上加载图片的Demo

    // // ZZTableViewController.m // 多图片下载 // // Created by Mac on 16/1/19. // Copyright © 2016年 Mac. Al ...

  9. 【LEETCODE OJ】Binary Tree Preorder Traversal

    Problem Link: http://oj.leetcode.com/problems/binary-tree-preorder-traversal/ Even iterative solutio ...

  10. Get Many Persimmon Trees_枚举&&二维树状数组

    Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aiz ...