0

I have a html text in

 <html>
 <head></head>
 <body>
  &lt;div id="carousel-generic" class="banner-erbj carousel slide" data-ride="carousel"&gt; &lt;ul class="carousel-indicators"&gt; &lt;li class="active" data-target="#carousel-generic" data-slide-to="0"&gt;0&lt;/li&gt; &lt;li data-target="#carousel-generic" data-slide-to="1"&gt;0&lt;/li&gt; &lt;/ul&gt; &lt;div class="carousel-inner"&gt; &lt;div class="item active"&gt;&lt;img src="imagesrcpath" alt="" /&gt;&lt;/div&gt; &lt;div class="item"&gt;&lt;img src="imagesrcpath" alt="" /&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; 
</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

beginner
  • 383
  • 3
  • 5
  • 19
  • try this http://www.survivingwithandroid.com/2014/04/parsing-html-in-android-with-jsoup-2.html – D.J Oct 19 '16 at 05:39
  • The link is dead Error 404 Not Found – beginner Oct 19 '16 at 05:41
  • 1
    In what way were you not able to find a solution? What have you tried (show your code, that failed with desired output)? Jsoup alone often fails due to lack of JavaScript support, but using a WebView and parsing the result with jsoup is a very good approach. – Frederic Klein Oct 19 '16 at 10:44
  • Possible duplicate of [Android - Parse JS generated urls with JSOUP](http://stackoverflow.com/questions/39140121/android-parse-js-generated-urls-with-jsoup) – Frederic Klein Oct 19 '16 at 10:46

4 Answers4

1

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.

beginner
  • 383
  • 3
  • 5
  • 19
-1

Use regex.

<img.+?/>

will simply find image tags.

Sung Min Lee
  • 154
  • 7
-1

Learn XPATH

http://www.w3schools.com/xml/xpath_intro.asp

and use your xpath knowledge in

http://htmlcleaner.sourceforge.net/, to get whatever you want from html

Kirtan
  • 1,782
  • 1
  • 13
  • 35
-1

You can take advantage of the power of REGEX here.

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.

2hamed
  • 8,719
  • 13
  • 69
  • 112