西西軟件園多重安全檢測(cè)下載網(wǎng)站、值得信賴的軟件下載站!
西西首頁(yè) 電腦軟件 安卓軟件 電腦游戲 安卓游戲 排行榜 專題合集

BookReptile.exe

附代碼
  • BookReptile.exe附代碼
  • 軟件大小:3.4M
  • 更新時(shí)間:2019-10-18 10:04
  • 軟件語(yǔ)言:中文
  • 軟件廠商:
  • 軟件類別:國(guó)產(chǎn)軟件 / 免費(fèi)軟件 / 瀏覽輔助
  • 軟件等級(jí):3級(jí)
  • 應(yīng)用平臺(tái):WinAll
  • 官方網(wǎng)站:暫無(wú)
  • 應(yīng)用備案:
好評(píng):50%
壞評(píng):50%

軟件介紹

BookReptile.exe是一款用go語(yǔ)言寫(xiě)的某書(shū)屋爬蟲(chóng),有代碼,有成品,大家笑納,今天寫(xiě)了一個(gè)書(shū)屋的爬蟲(chóng),獻(xiàn)給愛(ài)讀書(shū)的朋友們,該網(wǎng)站有兩種下載頁(yè),一個(gè)城通,一個(gè)百度云,城通沒(méi)有密碼,百度云含密碼,才學(xué)go語(yǔ)言,所以沒(méi)有去重功能,每次會(huì)重新新建txt文檔,之前爬好的數(shù)據(jù),注意保存哦.

主要功能

爬取書(shū)名+下載網(wǎng)址+密碼

使用說(shuō)明

這是單線程的,多線程,
多線程,直接go working(i)即可.
再加入channel通知主go程退出即可

爬蟲(chóng)之小說(shuō)爬取

軟件代碼

package main

import (

        "fmt"

        "io"

        "net/http"

        "os"

        "regexp"

        "strconv"

        "strings"

)

var count int

func main() {

        var start, end int

        fmt.Print("起始頁(yè)(>=1):")

        fmt.Scan(&start)

        fmt.Print("終止頁(yè)(>=起始頁(yè)[適度爬取,太多小心IP被封哦]):")

        fmt.Scan(&end)

        //創(chuàng)建文件

        fc,err:=os.Create("BookList.txt")

        if err!=nil{

                fmt.Println("os.Create err",err)

                return

        }

        fc.Close()

        //循環(huán)讀取每一頁(yè)

        for i := start; i <= end; i++ {

                working(i)

        }

        fmt.Println("爬取完畢,馬上閃開(kāi)!!!")

}

func working(idx int) {

        //打開(kāi)文件

        fo,err:=os.OpenFile("BookList.txt",os.O_APPEND,6)

        if err!=nil{

                fmt.Println("os.OpenFile err",err)

                return

        }

        defer fo.Close()

        url := "https://www.bukebook.cn/page/" + strconv.Itoa(idx)

        result, err := httpGet(url, idx)

        if err != nil {

                fmt.Println("檢查網(wǎng)絡(luò),或者IP被封了...")

                return

        }

        //正則處理信息獲得bookID

        //正則規(guī)則

        bookIDRule :=`class="greatwp-fp04-post-title"><a href="https://www.bukebook.cn/([0-9]+).html" rel="bookmark">`

        bookNameRule := `.html">《(?s:(.*?))</a></h2>`

        CTUrlRule := `<a class="ordown-button" href="(?s:(.*?))" target="_blank">城通網(wǎng)盤(pán)</a>`

        psdRule := `<strong>提取秘鑰: </strong>(?s:(.*?))   </br>`

        allID:=regexpData(result, bookIDRule)

        for i,tmpID:=range allID{

                bookID:=tmpID[1]

                //拼接下載頁(yè)URL

                dlUrl:="https://www.bukebook.cn/wp-content/plugins/ordown/down.php?id="+bookID

                //訪問(wèn)下載頁(yè)

                dlResult,err:=httpGet(dlUrl,i)

                if err!=nil{

                        fmt.Println("dl httpGet err",err)

                        return

                }

                //處理數(shù)據(jù)獲取書(shū)名,下載地址及密碼

                allBookName:=regexpData(dlResult,bookNameRule)

                allCTUrl:=regexpData(dlResult,CTUrlRule)

                allPsd:=regexpData(dlResult,psdRule)

                //fmt.Println(dlResult)

                for _,tmpBookName:=range allBookName{

                        bookName:=tmpBookName[1]

                        //判斷網(wǎng)盤(pán)類型

                        if strings.Contains(dlResult,"百度云盤(pán)"){

                                count++

                                //封裝百度網(wǎng)盤(pán)URL

                                BDUrl:="https://www.bukebook.cn/wp-content/plugins/ordown/download1.php?id="+bookID

                                //獲取網(wǎng)盤(pán)密碼

                                for _,tmpPsd:=range allPsd{

                                        //存儲(chǔ)書(shū)名及城通地址

                                        fo.Write([]byte(strconv.Itoa(count)+".《"+bookName+"\n"+BDUrl+"  "+tmpPsd[1]+"\n"))

                                        fmt.Println("《"+bookName+" 完成\n")

                                }

                        }else{

                                count++

                                //獲取城通網(wǎng)址

                                for _,tmpCTUrl:=range allCTUrl{

                                        //存儲(chǔ)書(shū)名及城通地址

                                        fo.Write([]byte(strconv.Itoa(count)+".《"+bookName+"\n"+tmpCTUrl[1]+"\n"))

                                        fmt.Println("《"+bookName+" 完成\n")

                                }

                        }

                }

        }

}

func regexpData(data, rule string) [][]string {

        reg := regexp.MustCompile(rule)

        return reg.FindAllStringSubmatch(data, -1)

}

func httpGet(url string, idx int) (result string, err error) {

        resp, err1 := http.Get(url)

        if err1 != nil {

                err = err1

                return

        }

        defer resp.Body.Close()

        buf := make([]byte, 4096)

        for {

                n, err2 := resp.Body.Read(buf)

                if n == 0 {

                        break

                }

                if err2 != nil && err2 != io.EOF {

                        err = err2

                        return

                }

                result += string(buf[:n])

        }

        return

}

其他版本下載

發(fā)表評(píng)論

昵稱:
表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
查看所有(0)條評(píng)論 > 字?jǐn)?shù): 0/500

TOP
軟件下載