Scrapping LINE stickers with Golang

Creating a quick script using Golang to scrap LINE stickers

Scrapping web

Why Golang

Speedrun tutorial

data-preview=”{ “type” : “popup_sound”, “id” : “312149456”, “staticUrl” : “https://stickershop.line-scdn.net/stickershop/v1/sticker/312149456/iPhone/sticker@2x.png;compress=true", “fallbackStaticUrl” : “https://stickershop.line-scdn.net/stickershop/v1/sticker/312149456/iPhone/sticker@2x.png;compress=true", “animationUrl” : “”, “popupUrl” : “https://stickershop.line-scdn.net/stickershop/v1/sticker/312149456/android/sticker_popup.png;compress=true", “soundUrl” : “https://stickershop.line-scdn.net/stickershop/v1/sticker/312149456/android/sticker_sound.m4a" }”
// Entrypoint
func main(){
consoleReader := bufio.NewReader(os.Stdin)
for {
fmt.Println(“Enter Line Stickershop URL”)
inputUrl, err := consoleReader.ReadString(‘\n’); if err != nil {
log.Fatal(err)
}
// Check if input has at least a line store format
if strings.Contains(inputUrl, “https://store.line.me") {
inputUrl = strings.Replace(inputUrl, “\r\n”, “”, -1)
err := scrap(inputUrl); if err != nil {
log.Fatal(err)
}
} else {
fmt.Println(“Invalid format”)
}
}
}
// Check if input has at least a line store format
if strings.Contains(inputUrl, “https://store.line.me") {
inputUrl = strings.Replace(inputUrl, “\r\n”, “”, -1)
err := scrap(inputUrl); if err != nil {
log.Fatal(err)
}
} else {
fmt.Println(“Invalid format”)
}
}
}
resp, err := http.Get(scrapUrl); if err != nil {
return err
}
var rgx = regexp.MustCompile(`(data-preview=’.*?’)`)
tmpExtracted := rgx.FindAllStringSubmatch(inputHtml, -1)
for i := 0; i < len(tmpExtracted); i++ {
// Parse the JSON here
type DataPreview struct {
Id string `json:”id”`
StickerType string `json:”type”`
PopupUrl string `json:”popupUrl”`
StaticUrl string `json:”staticUrl”`
AnimationUrl string `json:”animationUrl”`
SoundUrl string `json:”soundUrl”`
}
var wg sync.WaitGroup
for i := 0; i < len(result); i++ {
wg.Add(1)
go downloadImage(result[i], &wg)
}
```
WaitGroup basically just tells Madam Choo how many students has she assigned the task to.
defer wg.Done()
wg.Wait()
go build main.go

Final

--

--

I'm Jonathan Law Hui Hao, a Business Intelligence analyst in Malaysia who enjoys working with tech, RPA and Machine Learning!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jonathan Law

I'm Jonathan Law Hui Hao, a Business Intelligence analyst in Malaysia who enjoys working with tech, RPA and Machine Learning!