我正在用 colly 包制作一个网络抓取工具,它从一个网站收集ContestName和ContestTime制作一个 json 文件。
所以我喜欢这个
Contests := make(map[string]map[string]map[string]map[string]string)
Contests["AtCoder"] = make(map[string]map[string]map[string]string)
Contests["AtCoder"]["FutureContests"] = make(map[string]map[string]string)
AtcoderFunc(Contests)
.................code..........
func AtcoderFunc(Contests map[string]map[string]map[string]map[string]string) {
collector := colly.NewCollector(
colly.AllowedDomains("atcoder.jp", "www.atcoder.jp"),
)
// loc, _ := time.LoadLocation("Asia/Calcutta")
// format := "2006-01-02 15:04:05"
// var i int
format := "2006-01-02 15:04:05-0700"
loc, _ := time.LoadLocation("Asia/Calcutta")
for i := 1; i < 10; i++ {
ContestSelTime := fmt.Sprintf("#contest-table-upcoming div div table tbody tr:nth-child(%d) td:nth-child(1) a", i+1)
ContestSelName := fmt.Sprintf("#contest-table-upcoming div div table tbody tr:nth-child(%d) td:nth-child(2)", i)
// for contest name
collector.OnHTML(ContestSelName, func(element *colly.HTMLElement) {
ContestName := element.ChildText("a")
fmt.Printf("%T \n", ContestName)
fmt.Println(ContestName) // instead of printing i want to add it to the Contests["AtCoder"]["FutureContests"] map and print like json
})
// for contestTime
collector.OnHTML(ContestSelTime, func(element *colly.HTMLElement) {
ContestStartTime := element.ChildText("time")
parsed_time, _ := time.Parse(format, ContestStartTime)
IST_time := parsed_time.In(loc)
fmt.Println("Time in IST", IST_time) // instead of printing i want to add it to the Contests["AtCoder"]["FutureContests"] map.
})
}
但它给出了错误cannot use (map[string]string literal) (value of type map[string]string) as map[string]map[string]string value in assignment
任何想法?
宝慕林4294392
收到一只叮咚
随时随地看视频慕课网APP
相关分类