Go正则提取html A 连接标签

1import ( 2 "bufio" 3 "bytes" 4 "fmt" 5 "io/ioutil" 6 "net/http" 7 "os" 8 "regexp" 9 "strconv" 10 "strings" 11) 12func ListHref(html string) { 13 var hrefRegexp = regexp.MustCompile("(?m)<a.*?[^<]>.*?</a>") 14 match := hrefRegexp.FindAllString(html, -1) 15 if match != nil { 16 for i, v := range match { 17 fmt.Println("[", i, "]-", v) 18 } 19 } 20}
点赞
收藏

评论区

加载中...

相关推荐

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

Golang简单写文件操作的四种方法

packagemainimport("bufio"//缓存IO"fmt""io""io/ioutil"//io工具包"os")funccheck(eerror){ifenil{panic(e)}}/判断文件是否存在存在返回true不存在返回false/func

Go 正则表达式

packagemainimport"bytes"import"fmt"import"regexp"funcmain(){//这个测试一个字符串是否符合一个表达式。match,_:regexp.MatchString("p(az)ch","peach")fmt.Println(match)//上面我们是直接使

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

Golang 实现curl

  Linux很常用的curl命令,在golang中可以使用net/http来实现模拟get请求  funcGet(urlstring)(resp\Response,errerror)packagemainimport("fmt""io/ioutil"

go 协程

packageutilsimport("bytes""fmt""runtime""strconv")_/\__获取协程__ID\/_funcGetGoroutineID(){b:make(\\byte,64)b\b\:runtime.Stack(b,false)\b\