美文网首页
笔趣阁小说下载

笔趣阁小说下载

作者: 野小火 | 来源:发表于2018-03-14 17:15 被阅读16次
    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
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:笔趣阁小说下载

          本文链接:https://www.haomeiwen.com/subject/lwqkzxtx.html