添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Repository files navigation

Ktor: Jsoup

The Jsoup plugin allows you to handle xml and html content in your ktor application easily using the Jsoup library.

This plugin provides a HttpClientPlugin which provides a response transformer for the Jsoup Document type.

Usage

Install the plugin in your HttpClient

install(JsoupPlugin)

You can optionally configure more content types for Jsoup to parse

install(JsoupPlugin) {
    parsers[ContentType.Application.Rss] = Parser.xmlParser()

With the plugin installed you can receive Documents by using response.body<Document>().

HttpClient(engine) {
    install(JsoupPlugin) {
        parsers[ContentType.Application.Rss] = Parser.xmlParser()
}.use { client ->
    val feed = client.get(url).body<Document>()

Versions

Compatible / Recommended version pairings between ktor and ktor-jsoup

ktor-jsoup notes implementation "com.tfowl.ktor:ktor-jsoup:$ktorJsoupVersion" // Recommend overriding ktor & jsoup versions

Kotlin DSL

repositories {
    mavenCentral()
implementation("com.tfowl.ktor:ktor-jsoup:$ktorJsoupVersion")
// Recommend overriding ktor & jsoup versions

Add a maven dependency to your project:

<dependency>
  <groupId>com.tfowl.ktor</groupId>
  <artifactId>ktor-jsoup</artifactId>
  <version>${ktorJsoupVersion}</version>
</dependency>
<!-- Recommend overriding ktor & jsoup versions here -->

License

MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.