getall.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package main
  2. import (
  3. "archive/zip"
  4. _ "bytes"
  5. "fmt"
  6. "golang.org/x/net/html"
  7. "io"
  8. "net/http"
  9. "os"
  10. "strings"
  11. )
  12. // Download all CPUID dumps from http://users.atw.hu/instlatx64/
  13. func main() {
  14. resp, err := http.Get("http://users.atw.hu/instlatx64/?")
  15. if err != nil {
  16. panic(err)
  17. }
  18. node, err := html.Parse(resp.Body)
  19. if err != nil {
  20. panic(err)
  21. }
  22. file, err := os.Create("cpuid_data.zip")
  23. if err != nil {
  24. panic(err)
  25. }
  26. defer file.Close()
  27. gw := zip.NewWriter(file)
  28. var f func(*html.Node)
  29. f = func(n *html.Node) {
  30. if n.Type == html.ElementNode && n.Data == "a" {
  31. for _, a := range n.Attr {
  32. if a.Key == "href" {
  33. err := ParseURL(a.Val, gw)
  34. if err != nil {
  35. panic(err)
  36. }
  37. break
  38. }
  39. }
  40. }
  41. for c := n.FirstChild; c != nil; c = c.NextSibling {
  42. f(c)
  43. }
  44. }
  45. f(node)
  46. err = gw.Close()
  47. if err != nil {
  48. panic(err)
  49. }
  50. }
  51. func ParseURL(s string, gw *zip.Writer) error {
  52. if strings.Contains(s, "CPUID.txt") {
  53. fmt.Println("Adding", "http://users.atw.hu/instlatx64/"+s)
  54. resp, err := http.Get("http://users.atw.hu/instlatx64/" + s)
  55. if err != nil {
  56. fmt.Println("Error getting ", s, ":", err)
  57. }
  58. defer resp.Body.Close()
  59. w, err := gw.Create(s)
  60. if err != nil {
  61. return err
  62. }
  63. _, err = io.Copy(w, resp.Body)
  64. if err != nil {
  65. return err
  66. }
  67. }
  68. return nil
  69. }