简体   繁体   English

JSoup $登录ID标签

[英]JSoup $ sign in id tag

How can I use JSoup special characters in a tag attribute selector?. 如何在标签属性选择器中使用JSoup特殊字符?

For example: 例如:

id=HRS_CE_JO_EXT_I_HRS_JOB_OPENING_ID$1 

The usual selection syntax doesn't work: 通常的选择语法不起作用:

element.select("span#HRS_CE_JO_EXT_I_HRS_JOB_OPENING_ID$0"); 

Of course, as long as the special characters are towards the end, "start with" syntax can be used, but it is a kind-of-ugly work around.. 当然,只要特殊字符都在结尾,就可以使用“开头为”语法,但这是一种丑陋的解决方法。

You can try the attribute selector instead: 您可以尝试使用属性选择器

final String html = "<div id=HRS_CE_JO_EXT_I_HRS_JOB_OPENING_ID$1>A</div>";

Document doc = Jsoup.parse(html);

//                         whatever tag
//                             |
Element element = doc.select("div[id=HRS_CE_JO_EXT_I_HRS_JOB_OPENING_ID$1]").first();
//                                 |                  |
//                           attribute = id     attribute value

System.out.println(element);

Output: 输出:

<div id="HRS_CE_JO_EXT_I_HRS_JOB_OPENING_ID$1">
 A
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM