Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac3b24e

Browse files
committed
开源项目dom变更
1 parent e097ee7 commit ac3b24e

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/logic/project.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func (self ProjectLogic) ParseProjectList(pUrl string) error {
336336
return err
337337
}
338338

339-
const OsChinaDomain = "http://www.oschina.net"
339+
const OsChinaDomain = "https://www.oschina.net"
340340

341341
// ProjectLogoPrefix 开源项目 logo 前缀
342342
const ProjectLogoPrefix = "plogo"
@@ -360,8 +360,8 @@ func (ProjectLogic) ParseOneProject(projectUrl string) error {
360360
}
361361

362362
// 标题
363-
category := strings.TrimSpace(doc.Find("#v-header header .box-aw h1").Text())
364-
name := strings.TrimSpace(doc.Find("#v-header header .box-aw h1 span").Text())
363+
category := strings.TrimSpace(doc.Find(".detail-header h1 .project-title").Text())
364+
name := strings.TrimSpace(doc.Find(".detail-header h1 .project-name").Text())
365365
if category == "" && name == "" {
366366
return errors.New("projectUrl:" + projectUrl + " category and name are empty")
367367
}
@@ -383,8 +383,8 @@ func (ProjectLogic) ParseOneProject(projectUrl string) error {
383383
return nil
384384
}
385385

386-
logoSelection := doc.Find("#v-header header .logo img")
387-
if logoSelection.AttrOr("title", "") != "" {
386+
logoSelection := doc.Find(".detail-header .logo-wrap img")
387+
if logoSelection.AttrOr("alt", "") != "" {
388388
project.Logo = logoSelection.AttrOr("src", "")
389389

390390
if !strings.HasPrefix(project.Logo, "http") {
@@ -400,19 +400,19 @@ func (ProjectLogic) ParseOneProject(projectUrl string) error {
400400
}
401401

402402
// 获取项目相关链接
403-
doc.Find("#v-details .urls a").Each(func(i int, aSelection *goquery.Selection) {
404-
uri := util.FetchRealUrl(OsChinaDomain + aSelection.AttrOr("href", ""))
405-
switch aSelection.Find("span").Text() {
403+
doc.Find(".related-links a").Each(func(i int, aSelection *goquery.Selection) {
404+
uri := aSelection.AttrOr("href", "")
405+
switch aSelection.Text() {
406406
case "软件首页":
407407
project.Home = uri
408408
case "软件文档":
409409
project.Doc = uri
410-
case "软件下载":
410+
case "官方下载":
411411
project.Download = uri
412412
}
413413
})
414414

415-
doc.Find("#v-basic .list .box").Each(func(i int, liSelection *goquery.Selection) {
415+
doc.Find(".info-list .box .info-item").Each(func(i int, liSelection *goquery.Selection) {
416416
aSelection := liSelection.Find("span")
417417
txt := strings.TrimSpace(aSelection.Text())
418418
if i == 0 {
@@ -431,8 +431,13 @@ func (ProjectLogic) ParseOneProject(projectUrl string) error {
431431
project.Name = name
432432
project.Category = strings.TrimSpace(category)
433433
project.Uri = uri
434-
project.Repo = strings.TrimSpace(doc.Find("#v-details .github-widget").AttrOr("data-repo", ""))
435-
project.Src = "https://github.com/" + project.Repo
434+
project.Src = project.Download
435+
436+
if strings.HasPrefix(project.Src, "https://github.com/") {
437+
project.Repo = project.Src[len("https://github.com/"):]
438+
} else {
439+
project.Repo = project.Src[len("https://gitee.com/"):]
440+
}
436441

437442
pos := strings.Index(project.Repo, "/")
438443
if pos > -1 {
@@ -447,7 +452,10 @@ func (ProjectLogic) ParseOneProject(projectUrl string) error {
447452
}
448453

449454
desc := ""
450-
doc.Find("#v-details .detail").Find("p").Each(func(i int, domSelection *goquery.Selection) {
455+
doc.Find(".project-body").Children().Each(func(i int, domSelection *goquery.Selection) {
456+
if domSelection.HasClass("ad-wrap") {
457+
return
458+
}
451459
doc.FindSelection(domSelection).WrapHtml(`<div id="tmp` + strconv.Itoa(i) + `"></div>`)
452460
domHtml, _ := doc.Find("#tmp" + strconv.Itoa(i)).Html()
453461
if domSelection.Is("pre") {

0 commit comments

Comments
 (0)