A part of my HTML in my site (http://example.com) is:
//if my HTML code is:
<div class="text-co">
<div class="title">
00
11
22
</div>
</div>
<div class="text-co">
<div class="title">
33
44
55
</div>
</div>
and my android code is:
String url = "http://example.com";
ProgressDialog mProgressDialog;
#Override
protected Void doInBackground(Void... params) {
try {
Document document = Jsoup.connect(url).get();
Elements description = document.select("div[class=title] a");
desc = description.text();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
and I want to show '00' in first line and '11' in 2th line and so on.
For example: 00 11...
try:
Elements description = document.select("div[class=title]");
Elements aTags = description.select("a");
for(Element tag : aTags) {
String value = tag.text();
}
It's work with u?
Related
The thing is that I manage to bring a data that I want from the internet but it comes with a tag that I would like to remove. I get the data from here:
<a style="display: block;" class="btn-collapse" onclick="collapseChapter('collapsible490362')" role="button">
<i class="fa fa-chevron-down fa-fw"></i>
Capítulo 120.00
</a>
What interests me from there is the data: Capítulo 120.00. The problem is that in my application this looks like this:
This is how I bring the data:
protected ArrayList<TMODatosSeleccion> doInBackground(Void... voids) {
String url = getIntent().getStringExtra("valor");
tmoDatosSeleccions.clear();
try {
Document doc = Jsoup.connect(url).get();
Elements data = doc.select("div.col-10.text-truncate");
Elements dataDos = doc.select("div.col-2.col-sm-1.text-right");
for (Element e1 : data) {
for(Element e2 : dataDos){
String numeroCap = e1.select("a").html();
String urlManga = e2.select("a").attr("href");
tmoDatosSeleccions.add(new TMODatosSeleccion(numeroCap, urlManga));
}
}
} catch (IOException e) {
e.printStackTrace();
}
return tmoDatosSeleccions;
}
But this in my TextView looks like this:
<i class="fa fa-chevron-down fa-fw"></i> Capítulo 120.00
And like I said, I just want the: Cápitulo 120.00 to be seen
Does anyone know how I can fix it?
To select the text, use String numeroCap = e1.select("a").text() instead of html(). The html() method select everything inside the element.
public static void main(String[] args) {
String html = "<a style=\"display: block;\" class=\"btn-collapse\" onclick=\"collapseChapter('collapsible490362')\" role=\"button\"> <i class=\"fa fa-chevron-down fa-fw\"></i> Capítulo 120.00 </a>";
Document doc = Jsoup.parse(html);
String text = doc.select("a").text();
System.out.print(text);
}
I use this code but not true !!! why...?
String url = "http://example.com";
ProgressDialog mProgressDialog;
#Override
protected Void doInBackground(Void... params) {
try {
// Connect to the web site
Document document = Jsoup.connect(url).get();
// Using Elements to get the Meta data
Elements description = document
.select("div[class=title]");
// Locate the content attribute
desc = description.attr("content");
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
if my html code is
<div class="text-co">
<div class="title">00
11
22
</div>
</div>
<div class="text-co">
<div class="title">33
44
55
</div>
</div>
and I want to show
001122334455
in my android app by jsoup,What should I do
Try this code:
Elements anchors = document.select("div.title > a");
for(Element anchor : anchors) {
Strig description = anchor.text();
// ...
}
I am trying to get only one div (by class) to my webview. I don't know anything about PHP or CSS so i can't realize what should I do when i parse them by class name. I want to take
<div class="container_wrap container_wrap_first main_color fullsize">
part here but its so complicated so i really don't know what to write on doc.select(div. "HERE"). Thanks in advice.
Divs I Must Parse:
<div id="wrap_all">
<div class="mobil-logo">
<div id="main" data-scroll-offset="88">
<!--- header icerik sonu--->
<div class="container_wrap container_wrap_first main_color fullsize">
<div class="container">
And this is what I tried in Main.java:
// webview settings here
loadJsoup();
public void loadJsoup(){
try {
doc = Jsoup.connect("http://isvecehliyet.se/mobil").timeout(10000).get();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Element ele = doc.select("div.entry-content-wrapper").first();
String html = ele.toString();
String mime = "text/html";
String encoding = "utf-8";
mWebview.loadData(html, mime, encoding);
}
This works for me:
String url = "http://isvecehliyet.se/mobil/";
Document doc = Jsoup.connect(url).get();
Elements e = doc.select("div.container").first().parents();
System.out.println(e);
Part of output:
<div class="container_wrap container_wrap_first main_color fullsize">
<div class="container">
<main class="template-page content av-content-full alpha units" role="main" itemprop="mainContentOfPage">
<article class="post-entry post-entry [...]
I have this HTML:
<ul class="programList">
<li class="showing">
<div class="filterTime"></div>
<div class="filterGenre"></div>
<div class="outerSmallPoster">
<span class="posterBanner"></span>
<a href="/filmdatabase/06-juni/22-jump-street/">
<img src="/fileshare/filarkivroot/AuroraKino/Filmer/06%20-%20juni/22%20Jump%20Street/kynoefo11.jpg?width=160" class="smallPoster" /></a>
</div>
<div class="movieDescr">
<a class="movieTitle" href="/filmdatabase/06-juni/22-jump-street/">22 Jump Street</a>
<p class="movieDescription">Channing Tatum og Jonah Hill er tilbake i rollene som radarparet Jenko og Schmidt i oppfølgeren til...</p>
</div>
<div class="outerMovieDescription">
<div class="outerProgramTicketSale">
<button type="button" data-frames="underholdning" data-hour="21" href="http://91.207.226.164/ticketweb.php?sign=2&UserCenterID=100007&PaymentType=000&ShowID=484797&PaymentTypeSelection=&ErrorCode=0" target="_blank" onclick="openTicket(100007,484797);return false;" data-usercenterid="100007" data-showid="484797" class="programTime">
21:15
</button>
<span class="theater">Sal 6</span>
</div>
</div>
</li>
</ul>
This code is at a URL which I am trying to parse from an android app. To do so, I have written the following code:
protected Hashtable<String, Elements> doInBackground(Void... params) {
// Get all the movies from aurorakino and return a list of them
// to the postexecute method.
MainActivity.out("Bakgrunn");
Hashtable<String, Elements> map = new Hashtable<String, Elements>();
Document doc;
try {
doc = (Document) Jsoup.connect("http://fokus.aurorakino.no/billetter-og-program/").get();
Elements title = doc.select("a.movieTitle");
Elements desc = doc.select("p.movieDescription");
Elements image = doc.select("img.smallPoster");
MainActivity.out(title.size());
MainActivity.out("Vi er inne i try");
map.put("title", title);
map.put("desc", desc);
map.put("image", image);
return map;
}
catch (IOException e) {
// TODO Auto-generated catch block
MainActivity.out("Noe gikk galt");
}
return null;
}
This code is in an AsyncTask, and the task is running. I print some debug info from each stage in the asynctask so that I can see if its actually running. And it is.
My problem is that even though the html page has a few links like this:
movie title>
the code dont manage to find any of them. I print the element size and it says zero.
When i remove the class specification it finds 73 titles.
What am I doing wrong?
Many thanks
I Have been developing an Android RSS reader.I want to fetch the images from RSS feed and list them along with RSS title.I have parsed,and fetched data from "title" and "description" tags.Can Anyone tell me how to get the image URL from below "src" property of "description" ?
<item>
<title>Bollywood now more professional, but impersonal: Anupam Kher</title>
<link>
http://www.abcd.com/en/node/599
</link>
<description>
<div class=" field field-type-filefield field-field-story-image">
<div class="field-label">Image: </div>
<div class="field-items">
<div class="field-item odd">
<img class="imagefield imagefield-field_story_image" width="630" height="420" alt="" src="http://www.madhyamam.com/en/sites/default/files/anumpamkher2.jpg?1334148050" />
</div>
</div>
</div>
<p>
<strong>New Delhi: </strong>He has been part of the film industry for almost three decades.
</p>
read more
</description>
</item>
First of all, do the parsing in an AsyncTask. In this task you can simply download the images in the HTML/XML you load.
When you load the URL in the background you can call the following routine:
private Bitmap getImageFromURL(URL imgUrl){
Bitmap bmp = null;
try {
HttpURLConnection conn= (HttpURLConnection)imgUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bmp = BitmapFactory.decodeStream(is);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bmp;
}
I have found the solution.....
News news=new News();
String img = news.Description[i];
String cleanUp = img.substring(0, img.indexOf(">")+1);
img = img.substring(img.indexOf("src=") + 5);
int indexOf = img.indexOf("'");
if (indexOf==-1){
indexOf = img.indexOf("\"");
}
img = img.substring(0, indexOf);
news.image[i]=img;