main copy.go 826 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net/http"
  6. "regexp"
  7. "github.com/PuerkitoBio/goquery"
  8. )
  9. func main() {
  10. // Wordpress
  11. url := "https://addand.kr/shop/new-%ed%95%9c-%ea%b6%8c%ec%9c%bc%eb%a1%9c-%eb%81%9d%eb%82%98%eb%8a%94-%eb%85%b8%ec%85%98/"
  12. response, err := http.Get(url)
  13. if err != nil {
  14. log.Fatal(err)
  15. }
  16. defer response.Body.Close()
  17. doc, err := goquery.NewDocumentFromReader(response.Body)
  18. if err != nil {
  19. log.Fatal(err)
  20. }
  21. cEmail := "footer"
  22. // Define findEmail as an anonymous function
  23. findEmail := func(body string, doms string) (emails []string) {
  24. r, _ := regexp.Compile(`[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,24}`)
  25. emails = append(emails, r.FindStringSubmatch(body)...)
  26. return
  27. }
  28. fmt.Println("Email: ", findEmail(doc.Find(cEmail).First().Text(), ""))
  29. }