首页 > 解决方案 > jQuery 的第 n 个子方法等价于什么?

问题描述

我尝试编写第一个 google go 程序。我得到了这个工作部分:

package main

import (
    "fmt"
    "os"
    "regexp"

    "github.com/PuerkitoBio/goquery"
    "github.com/gocolly/colly"
)

func TrimSpaceNewlineInString(s string) string {
    re := regexp.MustCompile(` +\n+ +\t+`)
    return re.ReplaceAllString(s, "")
}

func main() {
    args := os.Args[1:]
    c := colly.NewCollector()
    c.OnHTML("tr",
        func(e *colly.HTMLElement) {
            ch := e.DOM.Children()
            spalte1 := ch.Eq(0)
            spalte2 := ch.Eq(1)

            spalte1.Each(
                func(_ int, s *goquery.Selection) {
                    fmt.Print(TrimSpaceNewlineInString(s.Text()), ":", TrimSpaceNewlineInString(spalte2.Text()))

                })
        })
    c.Visit("https://deweysearchde.pansoft.de/webdeweysearch/executeSearch.html" +
        "?lastScheduleRecord=669.1-669.7&lastTableRecord=&query=" + args[0] + "&_showShortNotations=off&catalogs=DNB&_catalogs=off&catalogs=GBV&_catalogs=off&catalogs=HeBIS&_catalogs=off&catalogs=SUB&_catalogs=off&catalogs=SWB&_catalogs=off&catalogs=FUB&_catalogs=off")
}

但是我只需要得到第二列,如果它在 [0-9.-] 范围内,如果是这样的话,我将需要下面的第三列以及这个 DOM HTMLElement 表的 DDC 分类。我想检索以下内容

            600;Technik
            660;Chemische Verfahrenstechnik
            669;Metallurgie
            669.1-669.7;Metallurgie einzelner Metalle und deren Legierungen
            669.1;Eisenmetalle

这里的任何人都可以帮助我并告诉我如何使用 colly Colly doc for go来完成,它类似于 jQuery?

PS:我已经尝试过这种方式 - 带孩子。但输出看起来像这样。我不知道为什么。

    Notation:Thema :


                        Haupttafeln
                    600:

                                    Technik

            660:

                                    Chemische Verfahrenstechnik

            661:

                                    Industriechemikalien

            661.2-661.6:

                                    Säuren, Basen, Salze

            661.5:

                                    Ammoniumsalze


            Notation:Thema :HilfstafelnT1--0:Hilfstafel 1. StandardschlüsselT2--0:Hilfstafel 2. Geo ... 

标签: go

解决方案


推荐阅读