**hi, i was trying obtain data from a page but i don't know how to obtain this data: Chapter 120 and de url link
This is the code from page (i simplified it):
<div class="row">
<div class="col-12">
<div class="card chapters" id="chapters">
<ul class="list-group list-group-flush">
<li class="list-group-item p-0 bg-light upload-link" data-index="0">
<h4 class="px-2 py-3 m-0">
<div class="row">
<div class="col-10 text-truncate">
<a style="display: block;" class="btn-collapse" onclick="collapseChapter('collapsible490362')" role="button"> Capítulo 120.00</a>
</div>
</div>
</h4>
<div style="display: block;" id="collapsible490362">
<div class="card chapter-list-element">
<ul class="list-group list-group-flush chapter-list">
<li class="list-group-item">
<div class="row">
<div class="col-2 col-sm-1 text-right">
<a href="https://lectortmo.com/view_uploads/599487" class="btn btn-default btn-sm">
<span class="fas fa-play fa-2x" style="color:#2957ba"></span>
</a>
</div>
</div>
</li>
</ul>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
In this line we can see the text (Chapter 120) that i need show in TextView but i don't know how to obtain it
<a style="display: block;" class="btn-collapse" onclick="collapseChapter('collapsible490362')" role="button"> Chapter 120</a>
And in this line we can see the url that i need:
<a href="https://lectortmo.com/view_uploads/599487" class="btn btn-default btn-sm">
This is my method to obtain data parsing:
#Override
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.row>.col-10");
int size = data.size();
Log.d("doc", "doc: "+doc);
Log.d("data", "data: "+data);
Log.d("size", ""+size);
for (Element e : data) {
String numeroCap = e.select("a").attr("none");
String urlManga = e.select("div.row>.col-2").select("a").addClass("btn").attr("href").trim();
tmoDatosSeleccions.add(new TMODatosSeleccion(numeroCap, urlManga));
}
} catch (IOException e) {
e.printStackTrace();
}
return tmoDatosSeleccions;
}
Someone can help me?
Print Screen:
You could get the two links you are trying to find using:
Elements data = doc.select("div.row a");
for (Element e : data)
{
// process the link
}
Or you could get them individually using:
Elements data = doc.select("div.row>.col-10 a");
if (data.size() == 1)
{
Element e = data.get(0);
// process col-10 link
}
data = doc.select("div.row>.col-2 a");
if (data.size() == 1)
{
Element e = data.get(0);
// process col-2 link
}
The main problem you were having was that the col-2 element was not nested inside the col-10 element, so your loop would not have found any items.
Related
I want to fetch sometitle and somelink from HTML code below for my android app ...
HELP ME :(
<div class="proper-list list-group page-cat-wrap">
<figure class="col-md-12 thumb-vertical">
<div class="col-xs-4 thumb-image">
<a href="/somelink.html" class="image-hover">
<img alt="SomeTag" src="/storage/images/100/2382.jpg">
</a>
</div>
<figcaption class="col-xs-8">
<h3>
<a href="/somelink.html">
SomeTitle
</a>
</h3>
<p>
<a href="/secondlink.html">
SomeText
</a>
</p>
</figcaption>
<div class="clearfix"></div>
<div class="mobile-only icon-right">
<a href="/somelink.html">
<i class="fa fa-chevron-right" aria-hidden="true"></i>
</a>
</div>
I heard of jsoup but won't able to get links with jsoup.
Jsoup is the best library to parse any of HTML content or document,
Here is the link and example,
http://jsoup.org/
Example
private void parsehtmlPage(){
File input = new File("/yourFolder/home.html");
Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");
Element elementId = doc.getElementById("elementId");
Elements ankerLinks = elementId.getElementsByTag("a");
for (Element link : ankerLinks) {
String linkHref = link.attr("href");
String linkText = link.text();
}
}
I have built a Cordova Android app using jQuery Mobile and Google Maps V3.
The Map works fine for some time, but when I try to zoom or drag the map for 4-5 times the app freezes. It only works again if I clean my cache/RAM. I have used custom markers, and marker positions are from a SQLite database.
<div data-role="page" data-theme="f" id="Gomap" style="width:100%; height:100%;">
<div role="banner" class="ui-bar-a ui-header" data-role="header" data-position="fixed" data-tap-toggle="false">
<a data-theme="f" href="branch_locator.html" data-rel="back" class="ui-btn-left ui-btn ui-btn-icon-left ui-btn-corner-all ui-shadow ui-btn-up-a" data-icon="arrow-l">
<span class="ui-btn-inner ui-btn-corner-all">
<span class="ui-btn-text">
Back
</span>
<span class="ui-icon ui-icon-arrow-l ui-icon-shadow">
</span>
</span>
</a>
<h1 aria-level="1" role="heading" tabindex="0" class="ui-title">
Google Map
</h1>
</div>
<div data-role="content" class="map" id="content">
<div id="map_canvas" style="height:100%;">
<div class="img-container"><img src="img/loading8.gif" /> </div>
</div>
</div>
<div data-role="footer" data-position="fixed" data-tap-toggle="false" class="foot">
</div>
<!-- /footer -->
<script type="text/javascript" src="js/map.js"></script>
</div>
map.js
var latt1;
var longg1;
var latt2;
var longg2;
$("#Gomap").on("pageshow", function(e) {
var s = $(this).data("url");
var lat1Part = s.split("&")[0];
var long1Part = s.split("&")[1];
var lat2Part = s.split("&")[2];
var long2Part = s.split("&")[3];
latt1 = lat1Part.split("=")[1];
longg1 = long1Part.split("=")[1];
latt2 = lat2Part.split("=")[1];
longg2 = long2Part.split("=")[1];
loadScript();
});
function initialize() {
$('#map_canvas').empty();
var ur_pos = new google.maps.LatLng(latt1, longg1);
var br_pos = new google.maps.LatLng(latt2, longg2);
$('#map_canvas').gmap();
$('#map_canvas').gmap({
'center': ur_pos
});
$('#map_canvas').gmap({
'zoom': 6
});
$('#map_canvas').gmap('addMarker', {
'position': br_pos,
'bounds': true,
'icon':'img/logo.png',
'animation': google.maps.Animation.DROP
}).click(function() {
$('#map_canvas').gmap('openInfoWindow', {
'content': '<B>Some Text Here</B>'
}, this);
});
$('#map_canvas').gmap('addMarker', {
'position': ur_pos,
'bounds': true,
'animation': google.maps.Animation.DROP
}).click(function() {
$('#map_canvas').gmap('openInfoWindow', {
'content': '<B>Your Current Position</B>'
}, this);
});
$('#map_canvas').gmap('refresh');
}
function loadScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://maps.googleapis.com/maps/api/js?key=GMAP KEY HERE&sensor=false&' +
'callback=initialize';
document.body.appendChild(script);
}
I'm trying to learn jsoup for android and I'm having a hard time with learning the selectors. I've already set up the application with simple buttons and textviews that can retrieve basic info i.e. title etc. Now I'm trying to get the text that I've highlighted below. I've tried multiple times and cannot get the correct syntax down.
<li class="info info info">
<script>clicked = false</script>
<div class="simple">
<p class="name">TEXT I NEED TO PARSE </p>
<ul class="Type">
<li>Normal</li> </ul>
<p class="address">120 Hollywood Blvd.</p>
</div>
<div class="sortables">
<p class="inches"></p>
</div>
<div class="action_links">
</div>
Document doc = null;
try {
doc = Jsoup.connect("http://example.com/index.html").get();
} catch (IOException e) {
// TODO Throws exception
}
Element simple = doc.getElementsByClass("simple").first();
Element p = simple.getElementsByClass("name").first();
Element a = p.select("a").first();
String text = a.text();
System.out.println(text);
I'm trying to load JSON from my wordpress-based website. I'm using phonegap to create an app on android, ios and windows. I'm using this js for the JSON, calling for business hours (shours1, shours2, shours3):
(function(){
'use strict';
var app = angular.module('app', ['onsen', 'angular-images-loaded', 'ngMap', 'angular-carousel']);
app.controller('restaurantController', function($http, $scope, $compile, $sce){
$scope.getHours = function(){
$scope.isFetching = true;
$scope.shours1 = '';
$scope.shours2 = '';
$scope.shours3 = '';
$http.jsonp('http://signsrestaurant.ca/api/get_posts/?post_type=restaurant&posts_per_page=-1&callback=JSON_CALLBACK').success(function(response) {
// Get's the first restaurant
$scope.restaurantJson = response.posts[0];
$scope.isFetching = false;
console.log( $scope.restaurantJson.custom_fields.shours1[0] );
$scope.shours1 = $scope.restaurantJson.custom_fields.shours1[0];
$scope.shours2 = $scope.restaurantJson.custom_fields.shours2[0];
$scope.shours3 = $scope.restaurantJson.custom_fields.shours3[0];
});
}
});
})();
Here is my html:
<ons-page ng-controller="restaurantController" ng-init="getHours()">
<ons-toolbar>
<div class="left">
<ons-toolbar-button ng-click="menu.toggle()"><ons-icon icon="ion-navicon-round" fixed-width="false"></ons-icon></ons-toolbar-button>
</div>
<div class="center">Location</div>
<div class="right" ng-show="isFetching">
<ons-toolbar-button><ons-icon icon="ion-loading-c" fixed-width="false" ></ons-icon></ons-toolbar-button>
</div>
</ons-toolbar>
<div class="app-page">
<div class="app-page-photo">
<ons-row class="app-map">
<ons-col>
<map center="[43.664639, -79.384649]">
<marker
position="[43.664639, -79.384649]"
title="Signs Restaurant & Bar"
animation="Animation.BOUNCE"
visible="true" ></marker>
</map>
</ons-col>
</ons-row>
<ons-list class="app-photo-buttons">
<ons-list-item modifier="action-buttons">
<ons-row class="action">
<ons-col class="action-col">
<div class="action-icon"><ons-icon icon="ion-ios-star-half"></ons-icon></div>
<div class="action-label">Rate</div>
</ons-col>
<ons-col class="action-col">
<div class="action-icon"><ons-icon icon="ion-bookmark"></ons-icon></div>
<div class="action-label">Favorite</div>
</ons-col>
<ons-col class="action-col">
<div class="action-icon" onclick="window.open('tel:647-428-3076', '_system', 'location=yes')"><ons-icon icon="ion-ios-telephone"></ons-icon></div>
<div class="action-label" onclick="window.open('tel:647-428-3076', '_system', 'location=yes')">Call</div>
</ons-col>
<ons-col class="action-col">
<div class="action-icon" onclick="window.open('http://maps.google.com/maps?q=43.664639,-79.384649', '_system', 'location=yes'), window.location('maps://maps.apple.com/?q=43.664639,-79.384649')"><ons-icon icon="ion-map"></ons-icon></div>
<div class="action-label" onclick="window.open('http://maps.google.com/maps?q=43.664639,-79.384649', '_system', 'location=yes'), window.location('maps://maps.apple.com/?q=43.664639,-79.384649')">Directions</div>
</ons-col>
</ons-row>
</ons-list-item>
</ons-list>
<ons-list modifier="inset" style="margin-top: 10px">
<ons-list-item>
<div class="app-open-desc">
<ons-icon icon="ion-android-clock"></ons-icon>
Monday <span class="label label-danger">{{ shours1 }}</span>
</div>
</ons-list-item>
<ons-list-item>
<div class="app-open-desc">
<ons-icon icon="ion-android-clock"></ons-icon>
Tuesday-Thursday <span class="label label-default">{{ shours2 }}</span>
</div>
</ons-list-item>
<ons-list-item>
<div class="app-open-desc">
<ons-icon icon="ion-android-clock"></ons-icon>
Friday-Sunday <span class="label label-default">{{ shours3 }}</span>
</div>
</ons-list-item>
</ons-list>
</div>
</div>
</ons-page>
It seems to be working partially. The shours do load, but only after I rotate my android or click on the menu. It doesn't load off-hand immediately. It basically needs some sort of a refresh to get it to load. I would appreciate it if someone can help me out with this.
Thanks a lot to Andreas Argelius. I wrapped the
$scope.shoursX
in
$scope.$evalAsync(function() { ... })
and that did it.
EDIT: I spoke too soon. It worked and it didn't. The issue still persists.
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