微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android中的Jsoup速度

如何解决Android中的Jsoup速度

我正在尝试在应用程序中显示librivox图书的图像列表。由于librivox api不提供书籍图片的网址,因此我必须通过抓取https://librivox.org/的html页面获取它们。下面的方法可以工作,但速度太慢(50本书的结果大约需要30秒)。有没有更好(更快)的方法来实现这一目标?

这是我在viewmodel中的方法

fun searchBooks(searchInput: String) {
    coroutinescope.launch {

        val deferredSearchResult = BookApi.retrofitService.getSearchResult(searchInput)
        val bookData = deferredSearchResult.await().books
        _listBooks.postValue(bookData.toBookItem())

    }
}

private fun List<Book>.toBookItem(): List<BookItem> {

    val bookList = mutablelistof<BookItem>()
    this.forEach {

        val imgurl = Jsoup.connect(it.url_librivox).get()
                .select("img")
                .get(1)
                .absUrl("src")

        Log.v(LOG_TAG,"imgurl is $imgurl")


        val bookAuthors: MutableList<String> = it.authors.map {
            it.first_name + "" + it.last_name
        }.toMutableList()

        bookList.add(BookItem(
            it.title,bookAuthors.toString(),it.url_librivox,imgurl
        ))
    }

    return bookList
}

解决方法

似乎网站速度异常慢。

尝试进入页面源,其中有相对URL,例如:

/app.php/feed?sid=

可以很容易地在主机之前添加

https://www.librivox.org/app.php/feed?sid= 并且看起来会话ID甚至没有用于限制访问,因此您可以继续删除查询参数以获取:

https://www.librivox.org/app.php/feed-加载速度非常快(相比)。

我在上面看不到您要使用哪个URL来获取书籍图像,因此很难建议是否有更好的URL供使用

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。