Created
November 12, 2013 16:50
-
-
Save pifantastic/7434385 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
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