jsoup
jsoup copied to clipboard
nth:child not limiting to range correctly in `p:nth-child(n+2):nth-child(-n+2)`
When processing a page http://ymammy.ru/category/dlya-mam/ , nth-child(2) does not work correctly. http://skrinshoter.ru/i/211118/U0Lo9X7F.png
hi guys, want do you want to get(html fragment) form the site, can tell us,
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.
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.
The selector does not work correctly, if there are hidden elements present such as <input type="hidden"/>
Please provide a fragment and the selector so anyone can replicate this. Best to use try.jsoup as mentioned.
<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!
(Confirmed in browser that p:nth-child(n+2):nth-child(-n+2)
will select just the second row)