Created
February 5, 2019 09:07
-
-
Save computerex/75f8b760df50914add3693c431ce367f to your computer and use it in GitHub Desktop.
fetches list of go packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"os" | |
"regexp" | |
) | |
func main() { | |
resp, err := http.Get("https://tip.golang.org/pkg/") | |
if err != nil { | |
fmt.Println(err) | |
} else { | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
fileStr := string(body) | |
fmt.Println(fileStr) | |
r := regexp.MustCompile("(<td class=\"pkg-name\" style=\"padding-left:.*)\\W+(<a href=)\"(.*)\">(.*)(</a>)") | |
matches := r.FindAllStringSubmatch(fileStr, -1) | |
for inx := range matches { | |
res := matches[inx] | |
pkg_link := res[3] | |
pkg_name := res[4] | |
fmt.Println(pkg_name, ": ", pkg_link) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment