Last active
December 17, 2015 15:59
-
-
Save shellac/5635892 to your computer and use it in GitHub Desktop.
Issue with jsoup addClass -- leading empty class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Set; | |
import org.jsoup.Jsoup; | |
import org.jsoup.nodes.Document; | |
import org.jsoup.nodes.Element; | |
public class Jsoup { | |
public static void main(String... args) throws Exception { | |
Document html = Jsoup.parse("<html><body><p>Bye</p><p class=\"baz\">Hi</p></body></html>"); | |
for (Element e: html.select("p")) { | |
e.addClass("foo"); | |
e.addClass("bar"); | |
System.out.println(e.attr("class")); | |
System.out.println(e.classNames()); | |
} | |
System.out.println(html.toString()); | |
System.out.println("".split("\\s+").length); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foo bar | |
[, foo, bar] | |
baz foo bar | |
[baz, foo, bar] | |
<html> | |
<head></head> | |
<body> | |
<p class=" foo bar">Bye</p> | |
<p class="baz foo bar">Hi</p> | |
</body> | |
</html> | |
1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment