Created
July 28, 2013 12:53
-
-
Save stianeikeland/6098475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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