Golang采集页面简单例子

Golang采集页面简单例子,第1张

概述package mainimport ( "fmt" "regexp" "net/http" "io/ioutil")func file_get_contents(url string) string{ r, e := http.Get(url) if e != nil { return "" } defe
package mainimport (  "fmt"	"regexp"	"net/http"	"io/IoUtil")func file_get_contents(url string) string{    r,e := http.Get(url)    if e != nil {        return ""    }    defer r.Body.Close()    c,e := IoUtil.ReadAll(r.Body)    if e != nil {        return""    }    return string(c)}func get_Title(url string,c chan string){	HTML:=file_get_contents(url)	r:= regexp.MustCompile(`<Title>([^<].+?)<\/Title>`)	rs:=r.FindStringSubmatch(HTML) 	c<-rs[1]}func main() {	u:=[]string{}	u=append(u,"http://www.oschina.net/news/41110/mozilla-firefox-weibo")	u=append(u,"http://www.oschina.net/news/41080/windows-phone-porting-challenge")	u=append(u,"http://www.oschina.net/news/41093/music-copyright")	u=append(u,"http://www.oschina.net/news/41109/rainweather-updated")	u=append(u,"http://www.oschina.net/news/41091/visual-studio-2013")	u=append(u,"http://www.oschina.net/news/41090/MysqL-5-6-12-ga")	u=append(u,"http://www.oschina.net/code/snippet_103482_15911")	u=append(u,"http://www.oschina.net/code/snippet_212240_21885")	u=append(u,"http://www.oschina.net/translate/PHP-best-practices")	u=append(u,"http://www.oschina.net/news/41053/whitehouse-programming-Hackathon")	u=append(u,"http://www.oschina.net/news/41035/androID-things-network")	u=append(u,"http://www.oschina.net/news/41037/github-announces-octokit")	u=append(u,"http://www.oschina.net/news/41032/linux-opensource-cpu-z")	u=append(u,"http://www.oschina.net/news/41051/writing-code-is-most-important-in-21-century")	u=append(u,"http://www.oschina.net/news/41077/15-page-Transitions-effects-tutorials-in-CSS3-and-jquery") 	l:=len(u)	c := make(chan string,2)	for i:=0;i<l;i++{		go get_Title(u[i],c)	}	for i:=0;i<l;i++{		fmt.Println(<-c);	}}
总结

以上是内存溢出为你收集整理的Golang采集页面简单例子全部内容,希望文章能够帮你解决Golang采集页面简单例子所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1292732.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-10
下一篇2022-06-10

发表评论

登录后才能评论

评论列表(0条)

    保存