使用skrape.it的HttpFetcher出现NoClassDefFoundError错误求助
问题解决:skrape.it HttpFetcher 出现 NoClassDefFoundError: io/ktor/client/features/HttpTimeout
问题原因
你遇到的错误是因为缺少Kotlin Ktor客户端的超时功能依赖包。当使用response代码块时,skrape.it的HttpFetcher会触发对Ktor超时相关类的调用,但你的依赖中仅引入了Ktor核心客户端,未包含超时模块,导致JVM找不到对应类。
解决方案
1. 补充Ktor超时依赖
在依赖配置中添加ktor-client-timeout模块,版本需与你使用的$ktor_version保持一致:
implementation("io.ktor:ktor-client-core:$ktor_version") implementation("io.ktor:ktor-client-timeout:$ktor_version") implementation("it.skrape:skrapeit:1.2.2")
2. 确保Ktor版本与skrape.it兼容
skrapeit 1.2.2内置依赖的Ktor版本为1.6.8,建议将$ktor_version设置为1.6.8,避免版本冲突引发其他潜在问题。
验证代码
修改依赖后,你的原有代码可正常运行:
fun getDocumentByUrl(urlToScrape: String) = skrape(HttpFetcher) { request { url = urlToScrape timeout = 10000 } response { htmlDocument { div(".title_table_routenliste") { findAll {}} } } }
内容的提问来源于stack exchange,提问作者Roger
相关产品推荐
相关产品推荐

