2020-02-02 23:45:13 -05:00
|
|
|
package eu.kanade.tachiyomi.util
|
2016-02-16 19:44:21 -05:00
|
|
|
|
2016-06-18 11:37:41 -04:00
|
|
|
import okhttp3.Response
|
|
|
|
import org.jsoup.Jsoup
|
|
|
|
import org.jsoup.nodes.Document
|
2016-02-16 19:44:21 -05: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-19 18:57:29 -04:00
|
|
|
fun Element.attrOrText(css: String): String {
|
|
|
|
return if (css != "text") attr(css) else text()
|
|
|
|
}
|
|
|
|
|
2016-06-18 11:37:41 -04: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 {
|
2020-01-05 11:29:27 -05:00
|
|
|
return Jsoup.parse(html ?: body!!.string(), request.url.toString())
|
|
|
|
}
|