I'd like to get a minimal CSS tree (not sure if that's correct term) for specific String of text.
By CSS tree I mean a set of selectors that will identify that particular text (or anything at the same level -- if there's a list of items with the same CSS then it's ok to get them all).
So for example let's say we have the following HTML:
<html>
<body>
<div id="someDivs">
<div class="a-row">My text</div>
<div class="a-row">Your text</div>
</div>
<div id="someOtherDivs">
<div class="main-div">Some other text</div>
</div>
</body>
</html>
If I specified the input as My text
then the minimal css tree
would be just .a-row
(this will match more than one item, but that's ok).
However if the HTML looked like:
<html>
<body>
<div id="someDivs">
<div class="a-row">My text</div>
<div class="a-row">Your text</div>
</div>
<div id="someOtherDivs">
<div class="main-div">
<div class="a-row">Some other text</div>
</div>
</div>
</body>
</html>
Then the minimal CSS tree for the input My text
would be #someDivs,.a-row
I think Javascript would be the easiest, but I'm pretty technology agnostic, if there's a better way to do this using backend tech (pref Java, but python etc are fine too) then that is not prob.
EDIT: The important thing is I'm trying to get the actual textual value of the selectors and not just get a variable (in JS) that can be used to select those items.