這是我的代碼(其中的一部分):type SitemapIndex struct { // Locations []Location `xml:"sitemap"` Locations []string `xml:"sitemap>loc"`}~~~ SNIP ~~~func main(){ var s SitemapIndex resp, _ := http.Get("https://www.washingtonpost.com/news-sitemaps/index.xml") bytes, _ := ioutil.ReadAll(resp.Body) xml.Unmarshal(bytes, &s) for _, Location := range s.Locations { fmt.Printf("%s\n", Location) resp, err := http.Get(Location) if err != nil { log.Fatal(err) } else { bytes, _ := ioutil.ReadAll(resp.Body) xml.Unmarshal(bytes, &n) for idx := range n.Titles { newsMap[n.Titles[idx]] = NewsMap{n.Keywords[idx], n.Locations[idx]} } } for idx, data := range newsMap { fmt.Println("\n\n\n", idx) fmt.Println("\n", data.Keyword) fmt.Println("\n", data.Location) } }現(xiàn)在,當(dāng)我運(yùn)行這段代碼時(shí),我得到了這個(gè)輸出:https://www.washingtonpost.com/news-sitemaps/politics.xml2019/01/28 02:37:13 parse https://www.washingtonpost.com/news-sitemaps/politics.xml: first path segment in URL cannot contain colonexit status 1我讀了一些帖子并自己做了一些實(shí)驗(yàn),比如我用下面的代碼制作了另一個(gè)文件package mainimport ("fmt" "net/url")func main(){ fmt.Println(url.Parse("https://www.washingtonpost.com/news-sitemaps/politics.xml"))}而且它沒(méi)有拋出任何錯(cuò)誤,所以我知道錯(cuò)誤與 url 無(wú)關(guān)?,F(xiàn)在,我?guī)讉€(gè)小時(shí)前才開(kāi)始使用 senddex 的教程學(xué)習(xí)Go,所以現(xiàn)在還不太了解。這是視頻鏈接
- 0 回答
- 0 關(guān)注
- 284 瀏覽
添加回答
舉報(bào)
0/150
提交
取消