get elements from html parser

隐身守侯 提交于 2019-12-11 03:59:30

问题


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 would be much appreciated.


回答1:


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.



来源:https://stackoverflow.com/questions/5950804/get-elements-from-html-parser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!