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);
}
Related
Hi I'm new in JSOUP and I need to retrieve a span value.
This is my html source:
<div class=" exactCenterlabel" style="font-size: xx-large">
<span id="labelfriends" style="display:inline-block;border-style:Outset;font-family:Guttman Yad-Brush;font-size:50pt;font-weight:bold;font-style:italic;height:115px;width:868px;margin-bottom: 0px">!תכיר מי הם החברים שלך </span>
</div>
I have tried this String value = doc.select("span#labelfriends").text();
But it doesn't retrieve what I want. Can you help?
Use This (Edited)
Use http://109.67.102.212:90/ as your url instead of http://knowyourfriend.ddns.net/ because it internally call http://109.67.102.212:90/ from frames
public static void main(String[] args) throws IOException {
Document doc = Jsoup.connect("http://109.67.102.212:90/").timeout(10000)
.userAgent("Mozilla/5.0")
.get();
System.out.println(doc.select("div.exactCenterlabel").select("span#labelfriends").text());
}
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?
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 am developing an android application in which I am parsing html contents from a website using Jsoup in android.
<meta name="title" content="Notices for the week - Holy Family Church, Pestom Sagar" />
For this I've wrote:
#Override
protected Void doInBackground(Void... params) {
try {
// Connect to the web site
org.jsoup.nodes.Document document = Jsoup.connect(url).get();
// Get the html document title
title=document.select("meta[name=title]");
desc = title.attr("content");
} catch (IOException e) {
e.printStackTrace();
} catch(NullPointerException ex){
System.out.println(ex);
}
return null;
}
#Override
protected void onPostExecute(Void result)
{
// Set title into TextView
t1.setText(desc);
}
This is working fine without any problem and displaying in textView of Activity. Now I want to parse h3 tag from that website.
<h3 xmlns="http://www.w3.org/1999/xhtml" id="sites-page-title-header" style="" align="left">
<span id="sites-page-title" dir="ltr">Notices for the week</span>
</h3>
I am not getting any idea how to do this and display this using TextView in android activity. Please suggest me...Also if I want to parse whole div tag and display that into activity using textView..!!!
You can select h3 tag directly as :
String h3=document. select("h3").text();
textView.setText(h3);
Or
textView. setText(document.select("span[id=sites-page-title]").first().text());