Created
August 28, 2016 22:54
-
-
Save juanpablocs/be392023cb5b70d546bf8ba153eefbc5 to your computer and use it in GitHub Desktop.
demo scraping vmuzice with golang
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" | |
"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