jsoup icon indicating copy to clipboard operation
jsoup copied to clipboard

nth:child not limiting to range correctly in `p:nth-child(n+2):nth-child(-n+2)`

Open agarkoff opened this issue 6 years ago • 7 comments

When processing a page http://ymammy.ru/category/dlya-mam/ , nth-child(2) does not work correctly. http://skrinshoter.ru/i/211118/U0Lo9X7F.png

agarkoff avatar Nov 21 '18 08:11 agarkoff

hi guys, want do you want to get(html fragment) form the site, can tell us,

bluetata avatar Dec 10 '18 02:12 bluetata

When processing a page http://ymammy.ru/category/dlya-mam/ , nth-child(2) does not work correctly. http://skrinshoter.ru/i/211118/U0Lo9X7F.png

I suggest that you go to https://try.jsoup.org/ and save it so that Jonathan or others can investigate effectively. Since the live url would change content and the screenshot also didn't provide necessary context information. At least you should provide input, expected output and actual output.

If this information can be provided I would also like to have a try to fix it - if it's proved to be a real issue.

ny83427 avatar Dec 14 '18 05:12 ny83427

Yeah, can you please send a fragment of the HTML so people can look into it/investigate? Without knowing what's in the "li" variable it's hard to see why JSoup fails. I can come up with multiple fragments that could work with the screenshot provided.

laxika avatar Dec 27 '18 18:12 laxika

The selector does not work correctly, if there are hidden elements present such as <input type="hidden"/>

Fachher avatar Mar 12 '20 13:03 Fachher

Please provide a fragment and the selector so anyone can replicate this. Best to use try.jsoup as mentioned.

jhy avatar Jan 04 '21 09:01 jhy

<html>
<head>
<title>Try jsoup</title>
</head>
<body>
<p>row1</p>
<p>row2</p>
<p>row3</p>
<p>row4</p>
</body>
</html>

selector: p:nth-child(n+2):nth-child(-n+2)

I want to get 2nd <p> tag only but returns row2,3,4. Instead of using nth-child(-n+x), I could get expected result by p:nth-child(n+2):lt(2). thanks!

utosh avatar Jun 14 '21 13:06 utosh

(Confirmed in browser that p:nth-child(n+2):nth-child(-n+2) will select just the second row)

jhy avatar Jan 06 '23 21:01 jhy