如何使用 Jsoup 提取节点 A 和节点 B 之间的任何节点?
How to extract any nodes between a node A and a node B with Jsoup?
我正在尝试从站点提取数据以构建数据库。
我想把"h2#1"的数据提取到"h2#2",
之前的那一行
并将其放入 Element 中,这样我就可以更轻松地处理数据。
图中显示的数据在一个div where id="left"
内
我要提取数据的页面:
http://koryaku.fullbokko.drecom.jp/quests/sp/eiketsu_sinka_no_hihou/netureinokishi/#1
试试这个 CSS 选择器:
h2#1 ~ *:not(h2#2 ~ *):not(h2#2)
演示
http://try.jsoup.org/~T29QSXFbJqwJx2a_If4qUeD1cnU
描述
h2#1 ~ * /* Select any node preceded by h2#1 ... */
:not(h2#2 ~ *) /* ... and not preceded by h2#2 ... */
:not(h2#2) /* ... and exclude h2#2 itself ! */
在 Jsoup 1.8.3 上测试
我正在尝试从站点提取数据以构建数据库。
我想把"h2#1"的数据提取到"h2#2",
之前的那一行
并将其放入 Element 中,这样我就可以更轻松地处理数据。
图中显示的数据在一个div where id="left"
内我要提取数据的页面:
http://koryaku.fullbokko.drecom.jp/quests/sp/eiketsu_sinka_no_hihou/netureinokishi/#1
试试这个 CSS 选择器:
h2#1 ~ *:not(h2#2 ~ *):not(h2#2)
演示
http://try.jsoup.org/~T29QSXFbJqwJx2a_If4qUeD1cnU
描述
h2#1 ~ * /* Select any node preceded by h2#1 ... */
:not(h2#2 ~ *) /* ... and not preceded by h2#2 ... */
:not(h2#2) /* ... and exclude h2#2 itself ! */
在 Jsoup 1.8.3 上测试