浏览代码

230927-1354-Kim

EricKIm 1 年之前
父节点
当前提交
6af9795877
共有 2 个文件被更改,包括 38 次插入0 次删除
  1. 38 0
      main copy.go
  2. 0 0
      main.go--

+ 38 - 0
main copy.go

@@ -0,0 +1,38 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	"net/http"
+	"regexp"
+
+	"github.com/PuerkitoBio/goquery"
+)
+
+func main() {
+	// Wordpress
+	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/"
+
+	response, err := http.Get(url)
+	if err != nil {
+		log.Fatal(err)
+	}
+	defer response.Body.Close()
+
+	doc, err := goquery.NewDocumentFromReader(response.Body)
+	if err != nil {
+		log.Fatal(err)
+	}
+
+	cEmail := "footer"
+
+	// Define findEmail as an anonymous function
+	findEmail := func(body string, doms string) (emails []string) {
+		r, _ := regexp.Compile(`[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,24}`)
+		emails = append(emails, r.FindStringSubmatch(body)...)
+
+		return
+	}
+
+	fmt.Println("Email: ", findEmail(doc.Find(cEmail).First().Text(), ""))
+}

+ 0 - 0
main.go → main.go--