百度一下手机号码,随便进一个网址。利用正则表达式获取这个网址的所有手机号码
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"regexp"
)
var (
Phonenumber = `1[3456789]\d{9}`
)
func HandleError(err error, when string) {
if err != nil {
fmt.Println(when, err)
os.Exit(1)
}
}
func main() {
resp, err := http.Get("http://www.gdhaoma.com/others/haoduans.asp?haoma=1316178")
HandleError(err, "http://www.gdhaoma.com/others/haoduans.asp?haoma=1316178")
bytes, _ := ioutil.ReadAll(resp.Body)
html := string(bytes)
//fmt.Println(html)
re := regexp.MustCompile(Phonenumber)
allString := re.FindAllStringSubmatch(html, -1)
fmt.Println(allString)
}
运行截图