多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
``` package main import ( "fmt" "io/ioutil" "net/http" "os" "strconv" "time" ) func work(start int , end int) { time.Sleep(time.Second * 1) for i:=start; i<=end; i++{ //抓取数据 url := "https://tieba.baidu.com/f?kw=%E7%BB%9D%E5%9C%B0%E6%B1%82%E7%94%9F&ie=utf-8&pn="+ strconv.Itoa((i-1)*50) data, err := http_get(url) if err != nil { fmt.Println("http get err : ", err) continue } //保存到文件 f, err := os.Create("第"+strconv.Itoa(i)+"页.html") if err != nil { fmt.Println("写入文件失败 : ", i, err) continue } f.WriteString(data) f.Close() } } func http_get(url string)(result string, err error) { resp, err := http.Get(url) if err != nil { return } data, err := ioutil.ReadAll(resp.Body) if err != nil { return } result = string(data) return } func main() { var start, end int fmt.Print("请输入起始页:") fmt.Scan(&start) fmt.Print("请输入终止页:") fmt.Scan(&end) //开始爬 work(start, end) } ```