package main
import (
"bufio"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
)
func main() {
var newurl string
input := bufio.NewScanner(os.Stdin)
fmt.Println("输入一个网址")
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("解析的网站:" + 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]
}
有疑问加站长微信联系(非本文作者)