我正在嘗試使用 go 制作網(wǎng)絡(luò)爬蟲(chóng)。我構(gòu)建了這段代碼。它構(gòu)建良好,沒(méi)有任何錯(cuò)誤。但它的二進(jìn)制文件不會(huì)執(zhí)行。這是大量例程或執(zhí)行函數(shù)中的那些變量的問(wèn)題嗎?package mainimport ( "io/ioutil" "net/http" //"regexp")func excuter(count int) { adrr := string("http://torhit.com/torbite/?page=" + string(count)) resp, _ := http.Get(adrr) bytes, _ := ioutil.ReadAll(resp.Body) ioutil.WriteFile("scrap.txt"+string(count), bytes, 0777) resp.Body.Close()}func main() { //re := regexp.MustCompile("") count := 1 maxcount := 200 for ; count <= maxcount; count++ { go excuter(count) }} package mainimport ( "io/ioutil" "net/http" //"regexp")func excuter(count int) { adrr := string("http://torhit.com/torbite/?page=" + string(count)) resp, _ := http.Get(adrr) bytes, _ := ioutil.ReadAll(resp.Body) ioutil.WriteFile("scrap.txt"+string(count), bytes, 0777) resp.Body.Close()}func main() { //re := regexp.MustCompile("") count := 1 maxcount := 200 for ; count <= maxcount; count++ { go excuter(count) }}
1 回答

幕布斯6054654
TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超7個(gè)贊
也許你的錯(cuò)誤來(lái)自這個(gè):
string(count)
它將編譯但結(jié)果為空。如果要將 int 轉(zhuǎn)換為 string,則需要 strconv 包。
strconv.Itoa(count)
或者
strconv.FormatInt(int64(count), 10)
- 1 回答
- 0 關(guān)注
- 154 瀏覽
添加回答
舉報(bào)
0/150
提交
取消