這是我的代碼(其中的一部分):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) } }現在,當我運行這段代碼時,我得到了這個輸出: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我讀了一些帖子并自己做了一些實驗,比如我用下面的代碼制作了另一個文件package mainimport ("fmt" "net/url")func main(){ fmt.Println(url.Parse("https://www.washingtonpost.com/news-sitemaps/politics.xml"))}而且它沒有拋出任何錯誤,所以我知道錯誤與 url 無關?,F在,我幾個小時前才開始使用 senddex 的教程學習Go,所以現在還不太了解。這是視頻鏈接
- 0 回答
- 0 關注
- 286 瀏覽
添加回答
舉報
0/150
提交
取消