Вот мой код (часть):
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.xml
2019/01/28 02:37:13 parse
https://www.washingtonpost.com/news-sitemaps/politics.xml
: first path segment in URL cannot contain colon
exit status 1
Я прочитал несколько постов и сделал несколькоСам поэкспериментирую, как будто я сделал другой файл со следующим кодом
package main
import ("fmt"
"net/url")
func main(){
fmt.Println(url.Parse("https://www.washingtonpost.com/news-sitemaps/politics.xml"))
}
И он не выдал никакой ошибки, поэтому я понимаю, что ошибка не с URL.
Теперь ятолько что начал изучать Go с помощью учебных пособий sentdex, несколько часов назад, и поэтому на данный момент понятия не имею.Вот видео ссылка
Спасибо и всего наилучшего.Temporarya