本文整理匯總了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
}