我使用JSOUP,并试图获得其与特定的div标签的ID开始的元素。例如:
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.
我看着 http://jsoup.org/cookbook/extracting-data/selector -syntax ,我尝试用多种变化:
I looked at http://jsoup.org/cookbook/extracting-data/selector-syntax and I tried a multiple variations using:
doc.select("div:matches(test(*))");
但它仍然没有奏效。任何帮助将是非常美联社preciated。
But it still didn't work. Any help would be much appreciated.
使用属性 - 开始 - 与选择 [ATTR ^ =值]
。
Use the attribute-starts-with selector [attr^=value]
.
Elements elements = doc.select("div[id^=test]");
// ...
这将返回所有&LT; DIV&GT;
与 ID元素
属性开始测试
。
This will return all <div>
elements with an id
attribute starting with test
.