package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"regexp"
)
var (
//3-30625-1970-04-26-0474
//reLink = `[1-6]\d{5}-(19\d{2})|(20(0\d)|(1[0-8]))-(0[1-9])|(1[012])-((0[1-9])|([12]\d)|(3[01]))-\d{3}[\dx]` //需要根据实际情况书写规则
reLink = `[1-6]\d{5}((19\d{2})|(20((0\d)|(1[0-8]))))(0[1-9])|(1[012])((0[1-9])|([12]\d)|(3[01]))\d{3}[\dx]` //需要根据实际情况书写规则
)
func HandleError(err error, when string) {
if err != nil {
fmt.Println(when, err)
os.Exit(1)
}
}
func main() {
html := GetHtml("http://www.shaoxing.com.cn/p/2771751.html")
re := regexp.MustCompile(reLink)
AallString := re.FindAllStringSubmatch(html, -1)
for _, x := range AallString {
fmt.Println(x[0])
}
}
func GetHtml(url string) string {
resp, err := http.Get(url)
HandleError(err, "http.Get")
bytes, _ := ioutil.ReadAll(resp.Body)
html := string(bytes)
return html
}
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
txttool.com 说一段 esp56物联 查询128 IP查询