Go正则提取html A 连接标签

Stella981
• 阅读 620
import (
    "bufio"
    "bytes"
    "fmt"
    "io/ioutil"
    "net/http"
    "os"
    "regexp"
    "strconv"
    "strings"
)
func ListHref(html string) {
    var hrefRegexp = regexp.MustCompile("(?m)<a.*?[^<]>.*?</a>")
    match := hrefRegexp.FindAllString(html, -1)
    if match != nil {
        for i, v := range match {
            fmt.Println("[", i, "]-", v)
        }
    }
}
点赞
收藏
评论区
推荐文章
易娃 易娃
3年前
Golang简单写文件操作的四种方法
packagemainimport("bufio"//缓存IO"fmt""io""io/ioutil"//io工具包"os")funccheck(eerror){ifenil{panic(e)}}/判断文件是否存在存在返回true不存在返回false/func
风斗 风斗
3年前
Go 正则表达式
packagemainimport"bytes"import"fmt"import"regexp"funcmain(){//这个测试一个字符串是否符合一个表达式。match,_:regexp.MatchString("p(az)ch","peach")fmt.Println(match)//上面我们是直接使
Stella981 Stella981
2年前
PhoneGap设置Icon
参考:http://cordova.apache.org/docs/en/latest/config\_ref/images.html通过config.xml中的<icon标签来设置Icon<iconsrc"res/ios/icon.png"platform"ios"width"57"height"57"densi
Stella981 Stella981
2年前
Golang 实现curl
  Linux很常用的curl命令,在golang中可以使用net/http来实现模拟get请求  funcGet(urlstring)(resp\Response,errerror)packagemainimport("fmt""io/ioutil"
Wesley13 Wesley13
2年前
go 协程
packageutilsimport("bytes""fmt""runtime""strconv")_/\__获取协程__ID\/_funcGetGoroutineID(){b:make(\\byte,64)b\b\:runtime.Stack(b,false)\b\
Stella981 Stella981
2年前
Go http访问使用代理
先写一段例子,例子是来自IRC gonuts的chentm,非常感谢他的帮助.packagemain import(    "fmt"    "net/http"    "net/url")funcmain(){    proxy:\func(\_\http.Requ
Stella981 Stella981
2年前
Go语言http服务器
下面的代码在helloworld的基础上,使用ioutil库做文件操作也能实现基础的服务了。packagemainimport(  "fmt"  "net/http"  "io/ioutil")funchandler(whttp.ResponseWriter,r\http
Stella981 Stella981
2年前
Golang读取目录文件
package mainimport(    "fmt"    "io/ioutil")func main() {        skillfolder : D:\go\        // 获取所有文件        files, _ : ioutil.Read
Stella981 Stella981
2年前
Sock 5 代理服务器
packagemain import(    "net"    "fmt"    "io"    "bytes"    "encoding/binary")typeMethodsstruct{    ver,nmethodsuint8    methods
Stella981 Stella981
2年前
Go 语言 bytes.FieldsFunc 函数的使用
packagemainimport("bytes""fmt""reflect""strings")funcmain(){sentence:byte("TheGolanguagehasbuiltinfac