贴出代码:
```
package main
import (
"fmt"
"strconv"
"github.com/PuerkitoBio/goquery"
)
func PrintProxy(url string) {
g, e := goquery.NewDocument(url)
if e != nil {
fmt.Println(e)
}
g.Find("tr").Each(func(i int, s *goquery.Selection) {
if i > 0 {
node := s.Find("td")
IP := node.Eq(0)
Port := node.Eq(1)
fmt.Printf("%v:%v\n", IP.Text(), Port.Text())
}
})
}
func main() {
url := "http://www.kuaidaili.com/free/inha/"
for i := 1; i < 5; i++ {
u := url + strconv.Itoa(i)
fmt.Println(u)
PrintProxy(u)
fmt.Println("++++++")
}
}
```
打印:
```
http://www.kuaidaili.com/free/inha/1
112.111.217.74:808
117.90.2.140:9000
++++++
http://www.kuaidaili.com/free/inha/2
++++++
http://www.kuaidaili.com/free/inha/3
++++++
http://www.kuaidaili.com/free/inha/4
++++++
```
为何只调用了一次函数?
有疑问加站长微信联系(非本文作者)