First sorry for my bad english. Im new in programming (2 year in collage). Im trying to get image from zomato. Yep, API only give us link. ( https://www.zomato.com/jakarta/ayam-keprabon-express-tambora/photos) so I need to manually get the image from web.
I already done this in iOS using Kana.
func parseHTML(html:String){
if let doc = Kanna.HTML(html: html, encoding: String.Encoding.utf8){
for show in doc.css("div[class^='photobox']"){
let getA = show.css("a").first
let image = getA!.css("img[class^='res-photo']").first?["data-original"]
let imageUrl = image!.components(separatedBy: "?")[0]
linkImageArray.append(imageUrl)
print("jumlah gambar = \(linkImageArray.count)")
}
}
foodCV.reloadData()
}
And my question how to do that in Jsoup?
This how i got HTML
Call<ResponseBody> photos = client.getPhotos();
photos.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {
if (response.isSuccessful()){
Log.i("retrofit: ","response "+response.body().toString());
getPhotos(response.body().toString());
}else{
Log.i("retrofit: ","notSuccess");
}
}
Now im stuck with this. Photobox.toString empty.
public void getPhotos(String stringResponse){
Document doc = Jsoup.parse(stringResponse);
Elements photobox = doc.getElementsByClass("container");
Log.i("html : ",""+photobox.toString());
Toast.makeText(this, photobox.toString(), Toast.LENGTH_SHORT).show();
for (Element data:photobox){
Log.i("html : ",""+data.select("img[class^='res-photo']"));
Log.i("html : ",""+data.select("img[class^='res-photo']").first().select("data-original"));
data.select("img[class^='res-photo']").first().select("data-original");
}
}
And im sure i cannot use this Jsoup: how to get an image's absolute url?. It will return all image. I would like to get img with 'data-original'.
<img class='res-photo-thumbnail thumb-load lazy-photo-inner'
src='https://b.zmtcdn.com/images/photoback.png'
title='Coffee Sisters - Coffee Sisters's photo'
alt='Coffee Sisters - Coffee Sisters's photo'
data-original='https://b.zmtcdn.com/data/reviews_photos/e4a/04b8e0669945bfe03fd0789cbd42be4a.jpg?fit=around%7C200%3A200&crop=200%3A200%3B%2A%2C%2A'
data-type='res'
data-photo_id='u_NDY5NzEwNzI1MD'
data-index='27'
data-category='all'
/>