go 爬取中国行政规划 半成品

func main() {
	resp, err := http.Get("http://www.mca.gov.cn/article/sj/xzqh/2020/2020/202003301019.html")
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	buf := bufio.NewReader(resp.Body)
	for {
		line, err := buf.ReadString('\n')
		if err != nil {
			if err == io.EOF {
				fmt.Println("File read ok!")
				break
			} else {
				fmt.Println("Read file error!", err)
				return
			}
		}
		line = strings.TrimSpace(line)
		if !strings.Contains(line,"mso-spacerun:yes"){
			continue
		}else{
			fmt.Println(line)
		}
	}
}

参考网址

http://www.mca.gov.cn/article/sj/xzqh/2020/2020/202003301019.html

你可能感兴趣的:(go)