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. nbtstat -a <IP> 会显示主机名、所在工作组等信息

    nbtstat -a <IP> 会显示主机名.所在工作组等信息

  2. 全国行政区划代码(json对象版)

    var area = {"110000":"北京市","110100":"北京市","110101" ...

  3. HTTP状态代码

    1xx(临时响应)表示临时响应并需要请求者继续执行操作的状态代码. 100 (继续) 请求者应当继续提出请求. 服务器返回此代码表示已收到请求的第一部分,正在等待其余部分. 101 (切换协议) 请求 ...

  4. 【转发】Linux下清除系统日志方法

    摘要:相信大家都是用过Windows的人.对于Windows下饱受诟病的各种垃圾文件都需要自己想办法删除,不然你的系统将会变得越来越大,越来越迟钝!windows怎么清理垃圾相信大家都知道的,那么li ...

  5. [转]shell基本算术运算

    from:http://www.cnblogs.com/yfanqiu/archive/2012/05/10/2494031.html#undefined shell程序中的操作默认都是字符串操作,在 ...

  6. LINQ基础(一)

    一.学习LINQ需要先了解以下知识点: 1.1 委托 1.2 匿名方法 1.3 Lambda表达式 1.4 扩展方法 二.LINQ原理:      from s in names where s.le ...

  7. poj2631 树的直径 + bfs

    //Accepted 492 KB 0 ms //树的直径 bfs #include <cstdio> #include <cstring> #include <iost ...

  8. (转)MyEclipse设置注释格式

    原文:http://xinghaifeng2006.iteye.com/blog/1243565 MyEclipse设置注释格式(转载)          博客分类: Java基础知识   Windo ...

  9. C++ Frequently asking question

    http://stackoverflow.com/questions/14295884/c-new-empty-project-how-to-create-it-add-main-method-and ...

  10. 黑马程序员——【Java基础】——Java概述

    ---------- android培训.java培训.期待与您交流! ---------- 一.Java语言概述及三大技术架构 1.Java语言概述 Java是SUN公司于1995年推出的一种面向I ...