How to get the HTML table from website on Android - android

I am new to Android Development and on my Android app, I want to retrieve HTML table values from website. I will use the values (in the background) which I'll get from the HTML table.
I want to get (td) values.
HTML table is like this.
<table width="482" height="187" cellspacing="1" cellpadding="1" border="1">
<tbody>
<tr>
<td> </td>
<td colspan="3" style="text-align:center;>
<strong>"UKOME KARARI</strong>
</td>
</tr>
<tr>
<td>Elektronik Bilet</td>
.....
</table>
Can I use the Jsoup? How?

You can use jsoup library inside your android application to achieve HTML table from web site.
Using this libray you can parse html page in Android.
Download jsoup library" from http://jsoup.org/download link.
Happy Coding...

Related

display:table-header-group does not work in Android webview

I have a long table which I want to print it. I need to repeat <th> on beging of every page so I use <thead>:
<table>
<thead>
<tr><th>heading</th></tr>
</thead>
<tfoot>
<tr><td>notes</td></tr>
</tfoot>
<tbody>
<tr><td>x</td></tr>
<tr><td>x</td></tr>
<!-- more rows -->
</tbody>
</table>
I search the web for repeating <thead> on each page and I found this css:
thead { display:table-header-group; }
tfoot { display:table-footer-group; }
so when I click print in firefox, I see the header on each page correctly, but when I open the document in Android and want to print it the header is not shown. Is there any solution or alternative way?
edit: this picture show my problem better:

JSoup not showing all the html in Java (td and tr tags missing)

I'm having trouble getting all the html code under the tags. Here is my current code:
Document document = Jsoup.connect("http://stackoverflow.com/questions/2971155/what-is-the-fastest-way-to-scrape-html-webpage-in-android").get();
Elements desc = document.select("tr");
System.out.println(desc.toString());
It's for that question, and I'm trying to get the text from the question's description. But I'm getting not getting certain tr or td tags like the ones for the question. Here is td tag I'm trying to get:
<td class="postcell">
Under that tag is the actual post. Now when I print out what I'm actually getting, I'm getting a ton of empty td tags and some comments, but not the actual post.
<tr id="comment-37956942" class="comment ">
<td>
<table>
<tbody>
<tr>
<td class=" comment-score"> </td>
<td> </td>
</tr>
</tbody>
</table> </td>
<td class="comment-text">
<div style="display: block;" class="comment-body">
<span class="comment-copy">You shouldn't parse HTML with regexes: blog.codinghorror.com/parsing-html-the-cthulhu-way</span> –
﹕ motobói
And it keeps on going with empty td and tr tags. I can't find the actual question. Anyone know why this is happening?
Essentially, I just want the text from the question's post, and I don't know how to get it, so it would be nice if someone could show me how to get the text.
Jsoup is a parser. That means that it can't execute any javascript code, that could generate html. When you encounter this problem the only way to retrieve that content is through a headless browser, that includes a javascript engine. A popular library is selenium webdriver.
In order to determine if the content you are trying to parse is generated in the server (static content) or in the client (dynamic content-javascript generated) you can do the following:
Visit the page you want to parse
Press Ctrl + U
The steps above will open a new tab that contains the content that jsoup receives. If the content you need is not there, then it's generated by javascript.
Follow the steps and search for the content. If it's there, but jsoup still has problems, then most probably the case is that the site considers you a bot or a mobile device. Try setting the userAgent of a desktop browser and see what happens.
Document document = Jsoup.connect("http://stackoverflow.com/questions/2971155/what-is-the-fastest-way-to-scrape-html-webpage-in-android").userAgent("USER_AGENT_HERE").get();
Most importantly, when the site exposes and API for the users to extract information programmatically then it's better to just use that.
Stackoverflow has an API available

webview save editable

how to save editable content loaded of local storage?
myWebView.loadUrl("file:///android_asset/www/table.html")
<table id="customers">
<tbody><tr class="alt"><th> </th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
</tr>
<tr class="alt"><td>1</td>
<td contenteditable='true'>asdasd</td>
<td contenteditable='true'>153213 </td>
<td contenteditable='true'>253625213</td>
<td contenteditable='true'>026426</td>
<td contenteditable='true' >asdasd</td>
</tr>
You can do this by first injecting a JavaScript-accessible POJO using WebView.addJavascriptInterface(). Your Android POJO would have the code to save the data. Then set up a JavaScript event listener to fire the POJO method. You could listen for a Done button click from the user or perhaps the new HTML5 input event.

ngmodel is not working with ngrepeat in android

input box not taking any field while it is surrounded in ngrepeat . in browser it is working perfectly but giving error while running in android as web view .
<div ng-repeat="teleOrderDetail in teleOrderDetails">
<table style="text-align:center;font-size:13px;width:98%;height:9%;">
<tr>
<td style="color:grey;width:33.34%;"><input type="tel" name="quantity" ng-model="teleOrderDetail.quantity" class="inputtd"></td>
</tr>
</table>
</div>
input type 'tel' appears to only be supported by Safari. This might be your problem with it displaying properly. Could you perhaps provide a little more information about the error if this isn't the problem?
See here: http://www.w3schools.com/html/html_form_input_types.asp

Parse HTML table using JSOUP and display it to listview

I am new in Android programming. I need to get values from HTML and display it in list.
Here is link http://www.hak.hr/info/cijene-goriva/
->so I need values (10,41,10.51)
<div id="div_eurosuper95">
<table class="nowrapper fuel_segmented">
<thead>
<tr>
<th>
Gorivo
</th>
<th>
Cijena (kn)
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="fuel_name"><span class="vendorName">Tifon</span></br>euroSUPER 95 BS</td>
<td class="fuel_segmented">10,41</td>
</tr>
<tr>
<td class="fuel_name"><span class="vendorName">Tifon</span></br>EUROSUPER 95
BS CLASS</td>
<td class="fuel_segmented">10,51</td>
</tr>
<tr>
<td class="fuel_name"><span class="vendorName">Crodux derivati</span></br>EUROSUPER 95 BS</td>
<td class="fuel_segmented">10,41</td>
</tr>
<tr>
<td class="fuel_name"><span class="vendorName">AdriaOil</span></br>Euro Super 95 BS TOP</td>
<td class="fuel_segmented">10,51</td>
</tr>
</tbody>
</table>
</div>
You can use Jsoup selector to select all the <td> tags that have are of class fuel_segmented.
Document doc = Jsoup.parse(html);
Elements fuel = doc.select("td.fuel_segmented");
This is a basic CSS selector syntax, where the td specifies the tag, and the . specifies that it is a class. If it was a specific td with an id you could've specified it as td#fuel_segmented.
This will return a collection of Element objects, represented by an Elements object.
To make it a bit more easy to see what is what, you can loop through the elements and display the corresponding fuel name.
Elements fuel = doc.select("td.fuel_segmented");
for (Element element : fuel) {
System.out.println(element.previousElementSibling().text()
+ ": " + element.text());
}
which will output
Tifon euroSUPER 95 BS: 10,41
Tifon EUROSUPER 95 BS CLASS: 10,51
Crodux derivati EUROSUPER 95 BS: 10,41
AdriaOil Euro Super 95 BS TOP: 10,51
I suggest that you read more about how to use the selector in Jsoup to parse the data that you need. That part of the cookbook can be found here.
To display your datas in ListView, there is a good tutorial to understand how does it work.
I really don't know where did you get these prices, on Jsoup you have all the "Cookbooks" necessary, with examples to parse html document.

Categories

Resources