package main
import (
"bufio"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
)
func main() {
var newurl string
input := bufio.NewScanner(os.Stdin)
fmt.Println("輸入一個(gè)網(wǎng)址")
input.Scan()
fmt.Println("你輸入的是:", input.Text())
var oldurl string = input.Text()
client := &http.Client{}
reqest, _ := http.NewRequest("GET", oldurl, nil)
reqest.Header.Set("User-Agent", "request")
response, _ := client.Do(reqest)
if response.StatusCode == 200 {
body, _ := ioutil.ReadAll(response.Body)
bodystr := string(body)
newurl = Between(bodystr, "https://aweme.snssdk.com", "&line")
newurl = "https://aweme.snssdk.com" + (strings.Replace(newurl, "playwm", "play", -1))
fmt.Println("解析的網(wǎng)站:" + newurl)
resp, err := http.Head(newurl)
if err != nil {
fmt.Println("err:", err)
}
defer resp.Body.Close()
fmt.Println(resp.Request.URL)
}
}
//取中間字符串
func Between(str, starting, ending string) string {
s := strings.Index(str, starting)
if s < 0 {
return ""
}
s += len(starting)
e := strings.Index(str[s:], ending)
if e < 0 {
return ""
}
return str[s : s+e]
}