Skip to content

Instantly share code, notes, and snippets.

@yukihir0
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save yukihir0/4983f523efeba329e38f to your computer and use it in GitHub Desktop.

Select an option

Save yukihir0/4983f523efeba329e38f to your computer and use it in GitHub Desktop.
GolangでRSSをパースする。
package main
import (
"fmt"
rss "github.com/jteeuwen/go-pkg-rss"
"os"
)
func main() {
timeout := 5
uri := "http://feeds.feedburner.com/hatena/b/hotentry"
feed := rss.New(timeout, true, chanHandler, itemHandler)
err := feed.Fetch(uri, nil)
if err != nil {
fmt.Fprintf(os.Stderr, "[e] %s: %s", uri, err)
return
}
}
func chanHandler(feed *rss.Feed, newchannels []*rss.Channel) {
fmt.Printf("%d new channel(s) in %s\n", len(newchannels), feed.Url)
}
func itemHandler(feed *rss.Feed, ch *rss.Channel, newitems []*rss.Item) {
fmt.Printf("%d new item(s) in %s\n", len(newitems), feed.Url)
for _, item := range newitems {
fmt.Println(item.Title)
for _, link := range item.Links {
fmt.Println(link.Href)
}
fmt.Println(item.Description)
fmt.Println("")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment