Skip to content

Instantly share code, notes, and snippets.

@stianeikeland
Created July 28, 2013 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stianeikeland/6098475 to your computer and use it in GitHub Desktop.
Save stianeikeland/6098475 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/PuerkitoBio/goquery"
"strconv"
"strings"
)
func GetFloridaFloat(datarows *goquery.Selection, field int) (data float64, err error) {
return strconv.ParseFloat(datarows.Eq(field).Children().Eq(1).Text(), 64)
}
func GetFloridaFloatClean(datarows *goquery.Selection, field int) (data float64, err error) {
tmp, _ := datarows.Eq(field).Children().Eq(1).Html()
clean := strings.Split(tmp, "<")[0]
return strconv.ParseFloat(clean, 64)
}
func main() {
doc, _ := goquery.NewDocument("http://veret.gfi.uib.no")
datarows := doc.Find(".obstable").First().Find("tr")
// Florida temperature
temperature, _ := GetFloridaFloat(datarows, 1)
wind, _ := GetFloridaFloatClean(datarows, 2)
rain, _ := GetFloridaFloat(datarows, 4)
humidity, _ := GetFloridaFloat(datarows, 5)
pressure, _ := GetFloridaFloat(datarows, 6)
fmt.Println(temperature, wind, rain, humidity, pressure)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment