惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
Engineering at Meta
Engineering at Meta
I
InfoQ
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
S
SegmentFault 最新的问题
H
Help Net Security
博客园 - 【当耐特】
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
腾讯CDC
雷峰网
雷峰网
Martin Fowler
Martin Fowler
The GitHub Blog
The GitHub Blog
D
Docker

博客园 - chensss2008

JavaScript 中的undefined and null 学习 html5 file upload and form data by ajax openresty + lua-resty-weedfs + weedfs + graphicsmagick动态生成缩略图(类似淘宝方案) ubuntu10.04 安装oracle server 版 笔记 windows xp + mysql5.5 + phpmyadmin insert 中文繁體 (原创)ubuntu 10.04+ruby1.9.2+rails3 安装记录 ruby簡單的代碼行統計工具 Ruby中如何复制对象 (deep clone)(转载) vi 常用命令使用說明 ruby1.9.2 +windowxp svn Server sent unexpected return value (403 Forbidden) in response to CHECKOUT ubuntu 14.04 安装svn server (subversionedge ) ubuntu 13.10 install wireshark Ubuntu 14.10下基于Nginx搭建mp4/flv流媒体服务器(可随意拖动)并支持RTMP/HLS协议(含转码工具) mysql distinct field1,field2,field3, .... from table jsoup 使用总结4--高级用法之 script js 脚本 jsoup 使用总结3--高级用法之 not jsoup 使用总结1--添加header require './ex25' can't load such file
jsoup 使用总结2--高级用法之 :gt(n)
chensss2008 · 2015-07-22 · via 博客园 - chensss2008

jsoup 使用总结2--高级用法之 :gt(n)

大部分时候,我们使用jsoup解析网页的时候,都是直接找到某一类元素,或者按某种selector查询;具体使用方法可以参考jsoup官网文档

部分html代码:

java代码:

Document doc = Jsoup.connect("www.example.com").timeout(0).get();
Elements links = doc.select("div.example_row").select("a");
for(Element link : links)
{
String linkHref = link.attr("href");
String linkText = link.text();
...
}
Element link = doc.select("a").first();
Element link_2 = doc.select("a").last();

如何我们想直接找到"政府政策"的DOM元素呢,有没有其他方式
当然有了,下面是代码:

Element link = doc.select("div.example_row").select("a:eq(4)");
// 4 对应 一个div example_row 下所以a元素的数组的下标
String linkText = link.text(); // 政府政策

当然这里的例子比较简单,但是eq(n)的用法我是交给你了呀。

同理还有:

:lt(n)
:gt(n)

希望能解决你手边的问题。

另外推荐阅读jsoup的官网文档,我80%的问题都在官网找到了方法。