本文整理汇总了Golang中github.com/PuerkitoBio/goquery.Document.FindSelection方法的典型用法代码示例。如果您正苦于以下问题:Golang Document.FindSelection方法的具体用法?Golang Document.FindSelection怎么用?Golang Document.FindSelection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/PuerkitoBio/goquery.Document
的用法示例。
在下文中一共展示了Document.FindSelection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ParseOneProject
//.........这里部分代码省略.........
_, err = MasterDB.Where("uri=?", uri).Get(project)
// 已经存在
if project.Id != 0 {
logger.Infoln("url", projectUrl, "has exists!")
return nil
}
logoSelection := doc.Find(".Project .PN img")
if logoSelection.AttrOr("title", "") != "" {
project.Logo = logoSelection.AttrOr("src", "")
if !strings.HasPrefix(project.Logo, "http") {
project.Logo = OsChinaDomain + project.Logo
}
project.Logo, err = DefaultUploader.TransferUrl(nil, project.Logo, ProjectLogoPrefix)
if err != nil {
logger.Errorln("project logo upload error:", err)
}
}
// 获取项目相关链接
doc.Find("#Body .urls li").Each(func(i int, liSelection *goquery.Selection) {
aSelection := liSelection.Find("a")
uri := util.FetchRealUrl(OsChinaDomain + aSelection.AttrOr("href", ""))
switch aSelection.Text() {
case "软件首页":
project.Home = uri
case "软件文档":
project.Doc = uri
case "软件下载":
project.Download = uri
}
})
ctime := time.Now()
doc.Find("#Body .attrs li").Each(func(i int, liSelection *goquery.Selection) {
aSelection := liSelection.Find("a")
txt := aSelection.Text()
if i == 0 {
project.Licence = txt
if txt == "未知" {
project.Licence = "其他"
}
} else if i == 1 {
project.Lang = txt
} else if i == 2 {
project.Os = txt
} else if i == 3 {
dtime, err := time.ParseInLocation("2006年01月02日", aSelection.Last().Text(), time.Local)
if err != nil {
logger.Errorln("parse ctime error:", err)
} else {
ctime = dtime.Local()
}
}
})
project.Name = name
project.Category = category
project.Uri = uri
project.Repo = strings.TrimSpace(doc.Find("#Body .github-widget").AttrOr("data-repo", ""))
project.Src = "https://github.com/" + project.Repo
pos := strings.Index(project.Repo, "/")
if pos > -1 {
project.Author = project.Repo[:pos]
} else {
project.Author = "网友"
}
if project.Doc == "" {
// TODO:暂时认为一定是 Go 语言
project.Doc = "https://godoc.org/" + project.Src[8:]
}
desc := ""
doc.Find("#Body .detail").Find("p").NextAll().Each(func(i int, domSelection *goquery.Selection) {
doc.FindSelection(domSelection).WrapHtml(`<div id="tmp` + strconv.Itoa(i) + `"></div>`)
domHtml, _ := doc.Find("#tmp" + strconv.Itoa(i)).Html()
if domSelection.Is("pre") {
desc += domHtml + "\n\n"
} else {
desc += html2md.Convert(domHtml) + "\n\n"
}
})
project.Desc = strings.TrimSpace(desc)
project.Username = PresetUsernames[rand.Intn(4)]
project.Status = model.ProjectStatusOnline
project.Ctime = model.OftenTime(ctime)
_, err = MasterDB.Insert(project)
if err != nil {
return errors.New("insert into open project error:" + err.Error())
}
return nil
}