I have a html text in
<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
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
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
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.
Related
I try this link
jSoup to check if a span class exists
but i want to get image url from the following script through jsoup.
<ul class="a-unordered-list a-nostyle a-button-list a-vertical a-spacing-top-micro">
<li class="a-spacing-small item"><span class="a-list-item">
<span class="a-declarative" data-action="thumb-action" data-thumb-action="{"variant":"MAIN","index":"0"}">
<span class="a-button a-button-selected a-button-thumbnail a-button-toggle a-button-focus"><span class="a-button-inner"><input class="a-button-input" type="submit"><span class="a-button-text" aria-hidden="true">
<img alt="" src="https://images-na.ssl-images-amazon.com/images/I/31XcCgGBePL._SS40_.jpg">
</span></span></span>
</span>
</span></li>
Try This :
Elements anchors = doc.select("li span img");
I have the following element in a webpage:
<div id="pnNij" class="post" data-tag1="" data-tag2="">
<a class="image-list-link" href="http://imgur.com/gallery/pnNij" data-page="0">
<img alt="" src="./Imgur_ The most awesome images on the Internet_files/H7fZCNgb.jpg">
<div class="point-info gradient-transparent-black transition">
<div class="relative">
<div class="pa-bottom">
<div class="arrows">
<div title="like" class="pointer arrow-up icon-upvote-outline" data="pnNij" type="image" data-up="4212"></div>
<div title="dislike" class="pointer arrow-down icon-downvote-outline" data="pnNij" type="image" data-downs="502"></div>
<div class="clear"></div>
</div>
<div class="point-info-points" title="points">
<span class="points-pnNij">3,710</span>
<span class="points-text-pnNij">points</span>
</div>
</div>
</div>
</div>
</a>
<div class="hover">
<p>Seems like 2017 has it all...</p>
<div class="post-info">
album · 69,542 views
</div>
</div>
</div>
notice how the href is equal to http://imgur.com/gallery/pnNij.
However, when I use JSoup to extract elements from the page like this:
docImgur = Jsoup.connect("http://imgur.com/").get();
Elements links = docImgur.getElementsByClass("post");
The element is almost extracted properly, except the href attribute is equal to /gallery/pnNij/
Why does the href attribute not contain the full URL?
When you check the page source, you'll find
<a class="image-list-link" href="/gallery/WRzti" data-page="0">
...
</a>
So the href attribute is not absolute, which results in your expected results: /gallery/WRzti
Solution
Use the abs: attribute prefix.
Example
Document docImgur = Jsoup.connect("http://imgur.com/").get();
Elements links = docImgur.select("a[href].image-list-link");
for (Element element : links) {
System.out.println(element.attr("abs:href"));
}
Output
http://imgur.com/gallery/WRzti
http://imgur.com/gallery/tCnDJ
http://imgur.com/gallery/JIHYh
...
<div class="item all clearfix">
<div class="pic all">
<a href="/terrace.jpg"/></a>
</div>
<div class="text all">
<a href="/link/test" class="title">
Some random title
</a>
<strong>STRONG TEXT</strong>
Some random subtitle…
</div>
</div>
I'm trying to get the text from the bold tag only, but whenever I parse it, it shows the complete. I also tried to remove the a class, but there was text left out below - "Some random subtitle".
I tried by:
Element strong_title = el.select("strong").first();
And then by retrieving strong_title.text().
Nevermind, it was a project-related code mistake.
The following code:
document.select("strong"); works just fine.
I have a JSP page, with some info pulled from Mongo DB. The outcome HTML page has UTF-8 encoding. Occasionally this char is being pulled from the DB: –, the en dash. When the page displayed in browser - this char is being displayed OK. But when in Android Webview - I see a question mark instead of it.
Any ideas how to solve it without touching the Mongo DB?
EDIT
Short HTML outcome:
<head>
<meta charset="utf-8">
....
</head>
...
<div class="photo_description">
<h1>
<span class="text-ellipsis">
NY – The sunrise
</span>
</h1>
<div class="button">
<div class="btn-txt">
View
</div>
</div>
...
</div>
...
Notice the dash in the <span> element.
I found an answer here:
${fn:escapeXml(photoTitle)}
I am new to web dev and android and am trying to develop a web app with phone gap and also using jquery mobile for that.
I am trying to view and display my webpage within the mobile screen with headers and footers also added through jquery code.
The code which i have written to display the webpage does display for eg http://www.msn.com but when i give for eg http://46.137.... (obviously thats a incomplete address) it does not work . Bytheway the alert is shown in both the cases. Below is the code
<div id="cnt" data-role="content">
<script>
$("#cnt").load("http://46.137....", function() {
alert('Load was performed.');
});
</script>
<!-- <iframe src="http://46.137...."></iframe> -->
</div><!-- /content -->
Hey #LivingThing try like this,
...
<div id="video1" data-role="content">
<iframe id="cnt" width="560" height="315" frameborder="0" allowfullscreen></iframe>
</div>
...
<script>
function l() {
document.getElementById('cnt').src = "http://www.cnn.com/US/index.html"
}
$(window).load(function() {
l()
alert('Load was performed.');
});
</script>
All this into <div data-role="page">
I hope this helps. :)