Created
February 20, 2018 11:21
-
-
Save steven-work-space/20bc1100b1b44447b601ac8b497918b2 to your computer and use it in GitHub Desktop.
Very simple crawler in Go to get the price of items on amazon France.
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" | |
"io/ioutil" | |
"net/http" | |
"regexp" | |
) | |
func main() { | |
//https://www.amazon.fr/gp/product/B0777XHSRJ/ | |
//https://www.amazon.fr/Amazon-Liseuse-Kindle-Paperwhite-6-Pouces-4Go/dp/B00QJDO0QC | |
resp, err := http.Get("https://www.amazon.fr/Amazon-Liseuse-Kindle-Paperwhite-6-Pouces-4Go/dp/B00QJDO0QC") | |
fmt.Println("http transport error is: ", err) | |
body, err := ioutil.ReadAll(resp.Body) | |
fmt.Println("read error is:", err) | |
r, _ := regexp.Compile(`<span id="priceblock_ourprice" class="a-size-medium a-color-price">EUR (\d*,*\d*)</span>`) | |
// Using FindStringSubmatch you are able to access the | |
// individual capturing groups | |
for index, match := range r.FindStringSubmatch(string(body)) { | |
fmt.Printf("[%d] %s\n", index, match) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment