scraping done
This commit is contained in:
parent
1c4885317a
commit
a82e78fdc7
1 changed files with 13 additions and 5 deletions
18
main.go
18
main.go
|
|
@ -9,6 +9,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/html"
|
||||
|
|
@ -87,8 +88,6 @@ func (mpv *MPV) InquirePlayback() (float32, error) {
|
|||
return res.Data, nil
|
||||
}
|
||||
|
||||
const PARSE_JSON_OFFSET = 25
|
||||
|
||||
func ParseWebMedia(url string) (string, error) {
|
||||
res, err := http.Get(url)
|
||||
if err != nil {
|
||||
|
|
@ -122,13 +121,22 @@ func ParseWebMedia(url string) (string, error) {
|
|||
for _, script := range scripts {
|
||||
if strings.Contains(script, "var streamChannels") {
|
||||
streamChannels = script
|
||||
break
|
||||
}
|
||||
}
|
||||
if streamChannels == "" {
|
||||
return "", fmt.Errorf("failed to find streamChannels")
|
||||
}
|
||||
|
||||
return streamChannels[25:], err
|
||||
re := regexp.MustCompile(`url:.*'(.*)'`)
|
||||
|
||||
if match := re.FindAllStringSubmatch(streamChannels, 1); match != nil {
|
||||
fmt.Println(match)
|
||||
|
||||
return match[0][1], nil
|
||||
} else {
|
||||
return "", fmt.Errorf("regex failed")
|
||||
}
|
||||
}
|
||||
|
||||
var testUrl string
|
||||
|
|
@ -148,6 +156,6 @@ func main() {
|
|||
// fmt.Println(err)
|
||||
// }
|
||||
|
||||
json, _ := ParseWebMedia(testUrl)
|
||||
fmt.Println(json)
|
||||
stream, err := ParseWebMedia(testUrl)
|
||||
fmt.Println(stream, err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue