国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
jsoup 的選擇器一覽表 - 開源中國社區(qū)

選擇器是 jsoup 用來從 html 文檔中對元素進行過濾的強大工具。

先看下面一段例子:

 

  1. File input = new File("/tmp/input.html");   
  2. Document doc = Jsoup.parse(input, "UTF-8""http://example.com/");   
  3.   
  4. Elements links = doc.select("a[href]"); // a with href   
  5. Elements pngs = doc.select("img[src$=.png]");   
  6.   // img with src ending .png   
  7.   
  8. Element masthead = doc.select("div.masthead").first();   
  9.   // div with class=masthead   
  10.   
  11. Elements 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 <fb:name> 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 finds p elements anywhere under a block with class "body"
  • parent > child: child elements that descend directly from parent, e.g. div.content > p finds p elements; and body > * finds the direct children of the body tag
  • siblingA + 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 than n; e.g. td:lt(3)
  • el:gt(n): find elements whose sibling index is greater than n; e.g. div p:gt(2)
  • el:eq(n): find elements whose sibling index is equal to n; 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.

相當(dāng)之強大,比我一直在用的 htmlparser 強多了。

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
小談Jsoup 選擇器查找方法
jsoup select 選擇器
使用 jsoup 對 HTML 文檔進行解析和操作
Jsoup解析HTML實例及文檔方法詳解
Jsoup選擇器規(guī)則
Jsoup使用總結(jié)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服