日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

jsoup的Elements类

發(fā)布時間:2024/8/23 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jsoup的Elements类 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、簡介

該類是位于select包下,直接繼承自O(shè)bject,所有實現(xiàn)的接口有Cloneable, Iterable, Collection, List

類聲明:public class Elements extends Object implements List, Cloneable

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

二、構(gòu)造方法

1、public Elements() 默認構(gòu)造方法
2、public Elements(int initialCapacity) 指定一個初始容量創(chuàng)建一個Elements對象。

3、public Elements(Collection elements) 使用已知元素集創(chuàng)建一個Elements對象。

4、public Elements(List elements) 使用已知元素的List集合創(chuàng)建一個Elements對象。

5、public Elements(Element… elements) 使用已知元素的可變參數(shù)列表創(chuàng)建一個Elements對象。

三、方法詳細

1、public Elements clone() 克隆

2、public String attr(String attributeKey) 根據(jù)鍵得到第一個匹配的元素(匹配即為有這個屬性)。

3、public boolean hasAttr(String attributeKey) 元素集中存在任何一個元素匹配(有這屬性)則返回true。

4、public Elements attr(String attributeKey, String attributeValue) 將 所有匹配attributeKey鍵的元素的值設(shè)置為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屬性上進行反轉(zhuǎn)。(有則移除,沒有則新增)。

9、public boolean hasClass(String className) 檢測是否有任何一個匹配的元素在class屬性有給定的className值。

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

11、public Elements val(String value) 對每一個匹配的元素設(shè)置表單值。

12、public String text() 得到所有匹配元素文本的綜合。該方法在某些情況下會得到重復(fù)數(shù)據(jù)。

13、public boolean hasText() 檢測是否有文本內(nèi)容

14、public String html() 得到所有匹配元素的內(nèi)部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) 設(shè)置每個匹配元素的內(nèi)部html。

19、public Elements prepend(String html) 將指定html增加到每個匹配元素的內(nèi)部html開頭。

20、public Elements append(String html) 將指定html增加到每個匹配元素的內(nèi)部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

,執(zhí)行這個包裝:doc.select(“b”).wrap(" ")后就變成:

This is jsoup

24、public Elements unwrap() 移除匹配的元素但保留他們的內(nèi)容。示例:

One Two 執(zhí)行 doc.select(“font”).unwrap() 變成: One Two
25、public Elements empty() 清空每個匹配元素的內(nèi)容。示例:

Hello there

now

執(zhí)行doc.select(“p”).empty() 變成

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

Hello

there

執(zhí)行doc.select(“p”).remove()后 變成

27、public Elements select(String query) 根據(jù)query選擇器查詢匹配的元素集。

28、public Elements not(String query) 移除匹配選擇器的元素集 返回過濾后的元素集。

29、public Elements eq(int index) 根據(jù)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) 對被查詢的元素執(zhí)行一次深度優(yōu)先的遍歷。

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

36、public boolean isEmpty() 檢測是否為空

37、public boolean contains(Object o) 檢測是否包含指定對象

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

39、public Object[] toArray() 將元素集轉(zhuǎn)換為數(shù)組

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) 根據(jù)索引得到指定元素

50、public Element set(int index, Element element) 根據(jù)索引設(shè)置指定元素

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

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

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

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

55、public ListIterator listIterator() 具體參照List

56、public ListIterator listIterator(int index) 具體參照List

57、public List subList(int fromIndex, int toIndex) 根據(jù)起始點得到子集

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

總結(jié)

以上是生活随笔為你收集整理的jsoup的Elements类的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。