Skip to content

Instantly share code, notes, and snippets.

@pifantastic
Created November 12, 2013 16:50
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 pifantastic/7434385 to your computer and use it in GitHub Desktop.
Save pifantastic/7434385 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
goquery "github.com/PuerkitoBio/goquery"
"sync"
"time"
)
var start = time.Now()
var totalPage = 200
var page = 1
var header = []string{"", "Rank", "Team", "Name", "Point", "Total"}
func fetch(page int) {
url := fmt.Sprintf("http://fantasy.premierleague.com/my-leagues/303/standings/?ls-page=%d", page)
var doc *goquery.Document
var e error
if doc, e = goquery.NewDocument(url); e != nil {
panic(e.Error())
}
table := doc.Find(".ismStandingsTable")
table.Find("tr").Each(func(x int, r *goquery.Selection) {
r.Find("td").Each(func(y int, t *goquery.Selection) {
if y == 2 {
//fmt.Printf("%s: %s\n", header[y], t.Text())
}
})
})
fmt.Printf("%d, %d\n", page, time.Since(start)/1E9)
}
func main() {
var wg sync.WaitGroup
fmt.Println("Page number, Time taken")
for page <= totalPage {
wg.Add(1)
go func(page int) {
defer wg.Done()
fetch(page)
}(page)
page++
}
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment