我正在嘗試使用 go 制作網絡爬蟲。我構建了這段代碼。它構建良好,沒有任何錯誤。但它的二進制文件不會執行。這是大量例程或執行函數中的那些變量的問題嗎?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貢獻1876條經驗 獲得超7個贊
也許你的錯誤來自這個:
string(count)
它將編譯但結果為空。如果要將 int 轉換為 string,則需要 strconv 包。
strconv.Itoa(count)
或者
strconv.FormatInt(int64(count), 10)
- 1 回答
- 0 關注
- 158 瀏覽
添加回答
舉報
0/150
提交
取消