drob50257447 2019-03-27 12:46
浏览 25

jQuery的第n个子方法等效于什么?

I try to program a first google go program. I got this working part:

package main

import (
    "fmt"
    "os"
    "regexp"

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

func TrimSpaceNewlineInString(s string) string {
    re := regexp.MustCompile(` +
+ +\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")
}

But I only what to get the 2nd column, if this is in the range form [0-9.-] and if so than I would need the following 3rd column with the DDC Classification of this DOM HTMLElement talbe. I would like to retrieve following

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

Can anyone here help me and tell me how it could be done with colly Colly doc for go, which is similar to jQuery?

PS: I have tried this way - with children. But the output looks like this. I do not know why.

    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 ... 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看