[英]parse the html and show it in webview android
I have a html text in 我有一个HTML文本
<html>
<head></head>
<body>
<div id="carousel-generic" class="banner-erbj carousel slide" data-ride="carousel"> <ul class="carousel-indicators"> <li class="active" data-target="#carousel-generic" data-slide-to="0">0</li> <li data-target="#carousel-generic" data-slide-to="1">0</li> </ul> <div class="carousel-inner"> <div class="item active"><img src="imagesrcpath" alt="" /></div> <div class="item"><img src="imagesrcpath" alt="" /></div> </div> </div>
</html>
</body>
I want to take out the link in it and display in a webview. 我想取出其中的链接并显示在网络视图中。 I have tried the jsoup method and some solutions provided in the questions on stackoverflow also but not able to find anysolution .. please help
我已经尝试过jsoup方法和stackoverflow问题中提供的一些解决方案,但找不到任何解决方案..请帮助
After lot more of digging i found the solution to it : 经过更多的挖掘,我找到了解决方案:
Spanned parsed = Html.fromHtml(text);
String finalstr = ("<html><body>").concat(parsed.toString()).concat("</body></html>");
mWebView.setInitialScale(30);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
/*mWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);*/
mWebVie.getSettings().setUseWideViewPort(true);
mWebView.loadData(finalstr, "text/html", "UTF-8");
This whole set of instructions helped me do the same. 这整套说明帮助我完成了同样的工作。
Use regex. 使用正则表达式。
<img.+?/>
will simply find image tags. 只会找到图像标签。
Learn XPATH 学习XPATH
http://www.w3schools.com/xml/xpath_intro.asp http://www.w3schools.com/xml/xpath_intro.asp
and use your xpath knowledge in 并在其中使用您的xpath知识
http://htmlcleaner.sourceforge.net/ , to get whatever you want from html http://htmlcleaner.sourceforge.net/ ,从html获取任何内容
You can take advantage of the power of REGEX
here. 您可以在此处利用
REGEX
。
Pattern pattern = Pattern.compile("/src=\"(.*)\"/");
Matcher matcher = pattern.matcher(YOURHTML);
matcher.group(1); // this way you can read all of the srcs
Disclaimer: the regex above is not tested. 免责声明:上面的正则表达式未经测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.