工作经历简介怎么写:jsoup 的选择器一览表 - 开源中国社区
来源:百度文库 编辑:中财网 时间:2024/04/19 13:00:22
选择器是 jsoup 用来从 html 文档中对元素进行过滤的强大工具。
先看下面一段例子:
源码copy to clipboard打印?
- File input = new File("/tmp/input.html");
- Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");
- Elements links = doc.select("a[href]"); // a with href
- Elements pngs = doc.select("img[src$=.png]");
- // img with src ending .png
- Element masthead = doc.select("div.masthead").first();
- // div with class=masthead
- Elements resultLinks = doc.select("h3.r > a"); // direct a after h3
File input = new File("/tmp/input.html");Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");Elements links = doc.select("a[href]"); // a with hrefElements pngs = doc.select("img[src$=.png]");// img with src ending .pngElement masthead = doc.select("div.masthead").first();// div with class=mastheadElements resultLinks = doc.select("h3.r > a"); // direct a after h3
下面是 jsoup 所支持的选择器列表:
Selector overview
tagname
: find elements by tag, e.g.a
ns|tag
: find elements by tag in a namespace, e.g.fb|name
finds
elements#id
: find elements by ID, e.g.#logo
.class
: find elements by class name, e.g..masthead
[attribute]
: elements with attribute, e.g.[href]
[^attr]
: elements with an attribute name prefix, e.g.[^data-]
finds elements with HTML5 dataset attributes[attr=value]
: elements with attribute value, e.g.[width=500]
[attr^=value]
,[attr$=value]
,[attr*=value]
: elements with attributes that start with, end with, or contain the value, e.g.[href*=/path/]
[attr=~regex
]: elements that have the attribute key, that its value matches the supplied regular expression; e.g.img[src~=(?i)\.(png|jpe?g)]
*
: all elements, e.g.*
Selector combinations
el#id
: elements with ID, e.g.div#logo
el.class
: elements with class, e.g.div.masthead
el[attr]
: elements with attribute, e.g.a[href]
- Any combination, e.g.
a[href].highlight
ancestor child
: child elements that descend from ancestor, e.g..body p
findsp
elements anywhere under a block with class "body"parent > child
: child elements that descend directly from parent, e.g.div.content > p
findsp
elements; andbody > *
finds the direct children of the body tagsiblingA + siblingB
: finds sibling B element immediately preceded by sibling A, e.g.div.head + div
siblingA ~ siblingX
: finds sibling X element preceded by sibling A, e.g.h1 ~ p
el, el, el
: group multiple selectors, find unique elements that match any of the selectors; e.g.div.masthead, div.logo
Pseudo selectors
el:lt(n)
: find elements whose sibling index (i.e. its position in the DOM tree relative to its parent) is less thann
; e.g.td:lt(3)
el:gt(n)
: find elements whose sibling index is greater thann
; e.g.div p:gt(2)
el:eq(n)
: find elements whose sibling index is equal ton
; e.g.form input:eq(1)
el:has(seletor)
: find elements that contain elements matching the selector; e.g.div:has(p)
el:contains(text)
: find elements that contain the given text. The search is case-insensitive; e.g.p:contains(jsoup)
el:matches(regex)
: find elements whose text matches the specified regular expression; e.g.div:matches((?i)login)
.- Note that all of the above indexed pseudo-selectors are 0-based, that is, the first element is at index 0, the second at 1, etc.
相当之强大,比我一直在用的 htmlparser 强多了。
4选1数据选择器的型号
急求JS写的时间选择器?
中国近当代著名作家原名一览表
中国主要影视城一览表 英文怎么说
求----历届中国美术家协会主席一览表
广西的成人高校一览表
MATLAB里simulink的“向量选择器”是那种器件?
波长选择器
世界最珍贵的物品一览表
广州可以收到的电台一览表
网吧经营许可证,各地的价钱一览表
上海所有的房地产公司一览表哪有?
谁知道北京汽车经销商的一览表???
VHDL语言用BLOCK语句写一个二选一的数据选择器
VHDL语言用BLOCK语句写一个二选一的数据选择器
VHDL语言用BLOCK语句写一个二选一的数据选择器
VHDL语言用BLOCK语句写一个二选一的数据选择器
VHDL语言用BLOCK语句写一个二选一的数据选择器
VHDL语言用BLOCK语句写一个二选一的数据选择器
realplayer的外观如何改变,它也有外观选择器吗?
求助RealPlayer声道选择器
我想了解 速度选择器
数据选择器设计
dreamweaver 标记选择器