Skip to content

Instantly share code, notes, and snippets.

@juanpablocs
Created August 28, 2016 22:54
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 juanpablocs/be392023cb5b70d546bf8ba153eefbc5 to your computer and use it in GitHub Desktop.
Save juanpablocs/be392023cb5b70d546bf8ba153eefbc5 to your computer and use it in GitHub Desktop.
demo scraping vmuzice with golang
package main
import (
"fmt"
"log"
"net/http"
"io/ioutil"
"regexp"
)
const URL = "http://vmuzice.com/mp3/salsa"
func main() {
// http request
res,err := http.Get(URL)
resbody, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
res.Body.Close()
str := string(resbody)
r,_ := regexp.Compile(`<span class="title">(.*?)<\/span>(?:.*\n\t.*\n\t.*\n\t.*)<a class="(?:.*?)" href="(.*?)" rel="nofollow">`)
for _, match := range r.FindAllStringSubmatch(str, -1) {
fmt.Printf("TITLE: %s, URL: %s\n", match[1], match[2])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment