Skip to content

Instantly share code, notes, and snippets.

@SunRunAway
Last active August 29, 2015 13:59
Show Gist options
  • Save SunRunAway/10449120 to your computer and use it in GitHub Desktop.
Save SunRunAway/10449120 to your computer and use it in GitHub Desktop.
cheapest-steam
/*
cheapest-steam
==============
A crawler to retrieve cheapest item price on steam.
```
go run main.go -url http://steamcommunity.com/market/listings/570/Taunt%3A%20Get%20Burned
```
*/
package main
import (
"strings"
"time"
"flag"
"fmt"
"github.com/PuerkitoBio/goquery"
)
var src = flag.String("url", "", "the url of your item")
var interval = flag.Int("interval", 3, "in second")
func main() {
flag.Parse()
url := *src
for ; ; time.Sleep(time.Duration(*interval)*time.Second) {
fmt.Printf("Getting lowest price at %v...\n", url)
doc, err := goquery.NewDocument(url)
if err != nil {
fmt.Printf("crawler error:", err)
continue
}
s := doc.Find(".market_listing_price_with_fee").First().Text()
s = strings.TrimSpace(s)
fmt.Println("============================================")
fmt.Printf("Lowest price is %v\n", s)
fmt.Println("============================================")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment