[英]Get URL from a HTML text in Android Java
String htmlText = Html.toHtml((Spanned) editText.getText());
//output of htmlText = "<span style="background-color:#F9F9F9;"><b><a href="someUrl">Some Text</a></b></span>"
How can I get the URL link in the <a>
tag so that I'll have something like我怎样才能在
<a>
标签中获取 URL 链接,以便我有类似的东西
String urlStr = "someUrl";
Okay... I was able to figure it out with the help of the comment from @CommonsWare.好的......我能够在@CommonsWare的评论的帮助下弄清楚。
First, I had to add the JSoup
library to my android project then with this code below首先,我必须将
JSoup
库添加到我的 android 项目中,然后使用下面的代码
String htmlText = Html.toHtml((Spanned) editText.getText());
Document doc = Jsoup.parse(htmlText, "UTF-8");
Elements element = doc.select("a");
String href = element.attr("href");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.