参考:http://www.cnblogs.com/majianguo/p/8186429.html
框架源码在 github.com/gocolly/colly
代码如下(源码中的demo)
package main import ( "fmt" "github.com/gocolly/colly" ) func main() { // Instantiate default collector c := colly.NewCollector( // Visit only domains: hackerspaces.org, wiki.hackerspaces.org colly.AllowedDomains("hackerspaces.org", "wiki.hackerspaces.org"), ) // On every a element which has href attribute call callback c.OnHTML("a[href]", func(e *colly.HTMLElement) { link := e.Attr("href") // Print link fmt.Printf("Link found: %q -> %s\n", e.Text, link) // Visit link found on page // Only those links are visited which are in AllowedDomains c.Visit(e.Request.AbsoluteURL(link)) }) // Before making a request print "Visiting ..." c.OnRequest(func(r *colly.Request) { fmt.Println("Visiting", r.URL.String()) }) // Start scraping on https://hackerspaces.org c.Visit("https://hackerspaces.org/") }
结果Ctrl-B后,提示了类似于cannot find package "github.com/PuerkitoBio/goquery" in any of:等一堆内容,对照提示用gopm逐一下载相应的依赖包,这时候真希望能用go get啊