import com.google.gson.*
import org.jsoup.*
import com.google.gson.JsonElement
import com.google.gson.JsonObject
fun getFilms(count: Int = 1): HashMap<Int, JsonObject> {
var n: Int = 0
val builder: GsonBuilder = GsonBuilder()
val gson = builder.create()
val ans = hashMapOf<Int, JsonObject>()
while (n <= count) {
val doc = Jsoup.connect("https://www.lostfilm.tv/ajaxik.php?act=serial&type=search&o=${n * 10}&s=3&t=0").get()
val data = doc.body().text().trimIndent()
val prData = JsonParser().parse(data).getAsJsonObject()
ans.put(n, prData)
n++
// println(prData["data"].toString().replace("[", "").replace("]", ""))
}
return ans
}
fun main(args: Array<String>) {
val films = getFilms(2)
films.forEach { (key, value) ->
var data = value.get("data").asJsonArray
data.forEach {
val obj = it.asJsonObject //since you know it's a JsonObject
val entries = obj.entrySet()
entries.forEach {
println("${it.key},${it.value}") //her is your key value
}
}
}
}
пример вывода:
rating,7.7
title,"Страна приливов"
title_orig,"Tidelands"
date,"2018"
link,"/series/Tidelands"
alias,"Tidelands"
not_favorited,true
id,"399"
has_icon,"1"
has_image,true
img,"//static.lostfilm.tv/Images/399/Posters/image.jpg"
genres,"Криминал, Драма, Мистика"
channels,"Netflix"
status,7
status_7,true
status_auto,2
status_auto_2,true
status_season,"1"
rating,8.2
title,"Летящие сквозь ночь"
title_orig,"Nightflyers"
date,"2018"
link,"/series/Nightflyers"
alias,"Nightflyers"
not_favorited,true
id,"398"
has_icon,"1"
has_image,true
img,"//static.lostfilm.tv/Images/398/Posters/image.jpg"
genres,"Ужасы, Драма, Фантастика"
channels,"Syfy"
status,7
status_7,true
status_auto,1
status_auto_1,true
status_season,"1"
rating,8.9
title,"Побег из Даннеморы"
title_orig,"Escape at Dannemora"
date,"2018"
link,"/series/Escape_at_Dannemora"