extract language from a web page with Jsoup

你离开我真会死。 提交于 2020-01-24 19:09:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!