[英]JSOUP generate css path and whitespace
I am trying to get css path of element from JSOUP document. 我正在尝试从JSOUP文档中获取元素的CSS路径。 This elemnt looks like this:
这个元素看起来像这样:
<div class="column" id="
datagrid147">
<div>
//Other data
</div>
</div>
Problem is whitespace in ID, when I get css selector from JSOUP element, it contains whitespace therefore is incorrect and when I remove whitespace, selector will not work for that element. 问题是ID中的空格,当我从JSOUP元素获取css选择器时,它包含空格,因此是不正确的,当我删除空格时,选择器将不适用于该元素。 So how to get correct css selector for element defined like this in JSOUP ?
那么如何为JSOUP中定义的元素获取正确的CSS选择器呢?
Proper solution would most likely involve cleaning attributes first (maybe with trim()
method), then selecting elements. 正确的解决方案很可能首先涉及清除属性(可能使用
trim()
方法),然后选择元素。
But way around could be using [attr~=regex]
selector, which in your case could look like div[id~=^\\\\s+datagrid147$]
. 但是可以使用
[attr~=regex]
选择器,在您的情况下,它看起来像div[id~=^\\\\s+datagrid147$]
。
Another way could be using [attr$=value]
where attribute attr
ends with specified value
like div[id$=datagrid147]
另一种方法是使用
[attr$=value]
,其中属性attr
以指定value
结尾,例如div[id$=datagrid147]
More help about selectors at: https://jsoup.org/cookbook/extracting-data/selector-syntax 有关选择器的更多帮助,请访问: https : //jsoup.org/cookbook/extracting-data/selector-syntax
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.