2,190
社区成员
发帖
与我相关
我的任务
分享
func main() {
models.Init()
for j:=390;j>0;j-- {
content ,err := models.Get_cate_urls("http://bbs.ecshop.com/forum-96-"+strconv.Itoa(j)+".html")
if (err !=nil) {
fmt.Println(err)
}
url_model := new(models.Urls)
for _,j :=range content {
url_model.Url = j
if url_model.Read("url") !=nil {
url_model.Status = 1
url_model.Insert()
} else {
fmt.Println(" have")
}
}
}
}
func geturls(j int ,c chan bool) {
//获取分类的里面的所有详细页面url
content ,err := models.Get_cate_urls("http://bbs.ecshop.com/forum-96-"+strconv.Itoa(j)+".html")
if (err !=nil) {
fmt.Println(err)
}
//数据库orm初始化
url_model := new(models.Urls)
for _,j :=range content {//循环插入每个分类采集的详细页面的url
url_model.Url = j
if url_model.Read("url") !=nil {
//如果采集的URL在数据库中不存在。就写入
url_model.Status = 1
url_model.Insert()
} else {
//如果数据库中存在,就跳过这条记录
fmt.Println(" have")
}
}
c<-true
}
func main() {
models.Init()
c := make(chan bool,390)
for j:=390;j>0;j-- {
//循环采集390个分类页面的详细url
go geturls(j,c)
}
for j:=390;j>0;j-- {
u:= <-c
fmt.Println(u)
}
close(c)
}