2016-02-17 01:44:21 +01:00
|
|
|
package eu.kanade.tachiyomi.util
|
|
|
|
|
2016-06-18 17:37:41 +02:00
|
|
|
import okhttp3.Response
|
|
|
|
import org.jsoup.Jsoup
|
|
|
|
import org.jsoup.nodes.Document
|
2016-02-17 01:44:21 +01:00
|
|
|
import org.jsoup.nodes.Element
|
|
|
|
|
|
|
|
fun Element.selectText(css: String, defaultValue: String? = null): String? {
|
|
|
|
return select(css).first()?.text() ?: defaultValue
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Element.selectInt(css: String, defaultValue: Int = 0): Int {
|
|
|
|
return select(css).first()?.text()?.toInt() ?: defaultValue
|
|
|
|
}
|
|
|
|
|
2016-06-18 17:37:41 +02:00
|
|
|
/**
|
|
|
|
* Returns a Jsoup document for this response.
|
|
|
|
* @param html the body of the response. Use only if the body was read before calling this method.
|
|
|
|
*/
|
|
|
|
fun Response.asJsoup(html: String? = null): Document {
|
|
|
|
return Jsoup.parse(html ?: body().string(), request().url().toString())
|
|
|
|
}
|