使用Jsoup从网页中提取语言 [英] extract language from a web page with Jsoup

查看:92
本文介绍了使用Jsoup从网页中提取语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我有

<html lang="en"> ...... web page </html>

我想用Jsoup提取字符串"en".

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());

推荐答案

看起来您想获取lang 属性的值.在这种情况下,您可以使用 attr("nameOfAttribute") 喜欢

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"));

这篇关于使用Jsoup从网页中提取语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆