简体   繁体   中英

How do I get the CSS selector of an element with Jsoup?

I have an element extracted from the DOM using JSOUP. I want to get the CSS selector of that element, so I can quickly find the equivalent elements on other pages with the same structure. Is this possible?

Thanks

I doubt that it's possible, because multiple selectors could be valid for your element -- eg, the trivial Selector.select("*",rootElement) would match it.

It sounds like you don't want to use the same element-extraction code (that you initially used) for all subsequent documents? If you're intent on using selectors, then perhaps try different ones until you find one that you're happy with (from either a readability or a performance perspective).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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