Skip to content

Instantly share code, notes, and snippets.

@bmitch
Created June 7, 2016 22:09
Show Gist options
  • Save bmitch/98b6b64152e0d13d1af154ddd85fd959 to your computer and use it in GitHub Desktop.
Save bmitch/98b6b64152e0d13d1af154ddd85fd959 to your computer and use it in GitHub Desktop.
weather scraper
package main
import (
"fmt"
"github.com/PuerkitoBio/goquery"
"log"
"strings"
)
func main() {
url := "http://www.victoriaweather.ca/station.php?id=93"
doc, err := goquery.NewDocument(url)
if err != nil {
log.Fatal(err)
}
doc.Find(".current_obs tr").Each(func(i int, s *goquery.Selection) {
title := s.Find("td").Eq(0).Text()
title = strings.Trim(title, " ")
value := s.Find("td").Eq(1).Text()
fmt.Printf("%15s %-40s\n", title, value)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment