笔趣阁小说下载

package downloadxiaoshuo

import okhttp3.OkHttpClient
import okhttp3.Request
import java.io.FileWriter
import java.io.StringReader
import java.io.StringWriter

val client = OkHttpClient()

fun genReq(nextSubUrl: String): Request {
    return Request.Builder()
            .url("http://www.biqukan.com/24_24845/$nextSubUrl")
            .build()

}


fun main(args: Array<String>) {

    var nextSubUrl = "8661600.html"
    var article = 1

    val writer = FileWriter("万剑道尊.txt")
//    val buffer = StringWriter()
//
    var count = 3
    while (true) {
        val string = client.newCall(genReq(nextSubUrl)).execute().body()?.string()
//    println(string)
        val sb = StringBuffer()
        StringReader(string).readLines().forEach {
            if (it.startsWith("var next_page =")) {
                val start = it.indexOf("\"") + 1
                val end = it.lastIndexOf("\"")
                nextSubUrl = it.substring(start, end).replace("/24_24845", "")
                print("第${article}篇:$nextSubUrl  ")
                article++
            }

            if (it.startsWith("<h1>")) {
                val title = it.replace("<h1>", "")
                        .replace("</h1>", "")
                print("标题:$title    ")
                sb.append(title).append("\n")
            }

            if (it.startsWith("<div id=\"content\" class=\"showtxt\">")) {
                val text = it.replace("<div id=\"content\" class=\"showtxt\">", "")
                        .replace("</div>", "")
                        .replace("<br />", "\n")
                        .replace("&nbsp;", " ")
                println("篇幅:${text.length}")
                sb.append(text).append("\n").append("\n").append("\n").append("\n").append("\n").append("\n")
                writer.write(sb.toString())
//            writer.flush()
                return@forEach
            }
        }
        if (nextSubUrl.isBlank()) {
            writer.flush()
            return
        }
    }
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容