开发者

get elements from html parser

开发者 https://www.devze.com 2023-03-04 17:05 出处:网络
I\'m using JSOUP, and trying to get the elements which start with a particular div tag id. For example:

I'm using JSOUP, and trying to get the elements which start with a particular div tag id. For example:

<div id="test123">. 

I need to check if the elements starts with the string "test" and get all the elements.

I looked at http://jsoup.org/cookbook/extracting-data/selector-syntax and I tried a multiple variations using:

doc.select("div:matches(test(*))");

But it still didn't work. Any help wo开发者_开发技巧uld be much appreciated.


Use the attribute-starts-with selector [attr^=value].

Elements elements = doc.select("div[id^=test]");
// ...

This will return all <div> elements with an id attribute starting with test.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号