如何解决在 Kotlin Android 中阅读 webview 内容
我需要阅读 Webview 中显示的内容。我有一个案例,我需要调用 webview 来输入密码,成功时返回 json 响应。现在,如果在 webview 屏幕本身中打印,则 json 响应。尝试使用 webview 函数读取响应
override fun onPageFinished(view: WebView?,url: String?) {
super.onPageFinished(view,url)
try {
val aURL = URL(url)
val conn: URLConnection = aURL.openConnection()
conn.connect()
val inputStream: InputStream = conn.getInputStream()
htmlContent = convertToString(inputStream)
}
catch (exception:Exception){
print(exception)
}
}
执行 conn.getInputStream()
时导致 File not found 异常。在 onPageCommitVisible
函数中也尝试了相同的方法。结果一样。
还尝试使用 implementation 'org.jsoup:jsoup:1.11.2'
读取响应。但它会抛出 404 错误。
val stringBuilder = StringBuilder()
try {
val doc: Document = Jsoup.connect(url).get()
print(doc)
} catch (e: IOException) {
print(e)
}
页面加载完成后有没有办法读取页面内容。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。