Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sokomishalov committed Oct 14, 2019
1 parent d887ccc commit 9b720f5
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,38 @@

package ru.sokomishalov.commons.core.html

import io.netty.handler.codec.http.HttpHeaderNames.USER_AGENT
import org.jsoup.Jsoup.clean
import org.jsoup.Jsoup.parse
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import org.jsoup.safety.Whitelist
import ru.sokomishalov.commons.core.http.REACTIVE_NETTY_HTTP_CLIENT
import ru.sokomishalov.commons.core.reactor.awaitStrict
import ru.sokomishalov.commons.core.string.isNotNullOrBlank
import java.nio.charset.StandardCharsets.UTF_8


/**
* @author sokomishalov
*/
suspend fun getWebPage(url: String): Document {
val document = REACTIVE_NETTY_HTTP_CLIENT
suspend fun getWebPage(
url: String,
userAgent: String? = null
): Document {
return REACTIVE_NETTY_HTTP_CLIENT
.headers {
if (userAgent.isNotNullOrBlank()) {
it.set(USER_AGENT, userAgent)
}
}
.get()
.uri(url)
.responseContent()
.aggregate()
.asString(UTF_8)
.awaitStrict()

return parse(document)
.let { parse(it) }
}

fun Element.getSingleElementByClass(name: String): Element {
Expand Down

0 comments on commit 9b720f5

Please sign in to comment.