问题
For example I have
<html lang="en"> ...... web page </html>
I want to extract the string "en" with Jsoup.
I tried with selector and attribute without success.
Document htmlDoc = Jsoup.parse(html);
Element taglang = htmlDoc.select("html").first();
System.out.println(taglang.text());
回答1:
Looks like you want to get value of lang attribute. In that case you can use attr("nameOfAttribute") like
System.out.println(taglang.attr("lang"));
来源:https://stackoverflow.com/questions/29390378/extract-language-from-a-web-page-with-jsoup