MCPcopy Create free account
hub / github.com/Le0nsec/SecCrawler / Get

Method Get

crawler/EdgeForum.go:24–82  ·  view source on GitHub ↗

Get 获取棱角社区前24小时内文章。

()

Source from the content-addressed store, hash-verified

22
23// Get 获取棱角社区前24小时内文章。
24func (crawler EdgeForum) Get() ([][]string, error) {
25 client := utils.CrawlerClient()
26
27 req, err := http.NewRequest("GET", "https://forum.ywhack.com/forumdisplay.php?fid=59&orderby=lastpost&filter=86400", nil)
28 if err != nil {
29 return nil, err
30 }
31
32 req.Header.Set("Cache-Control", "max-age=0")
33 req.Header.Set("Upgrade-Insecure-Requests", "1")
34 req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36")
35 req.Header.Set("Sec-Fetch-Dest", "document")
36 req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
37 req.Header.Set("Sec-Fetch-Site", "none")
38 req.Header.Set("Sec-Fetch-Mode", "navigate")
39 req.Header.Set("Sec-Fetch-User", "?1")
40 req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9")
41 resp, err := client.Do(req)
42 if err != nil {
43 return nil, err
44 }
45 defer resp.Body.Close()
46
47 body, err := ioutil.ReadAll(resp.Body)
48 if err != nil {
49 return nil, err
50 }
51
52 bodyString := string(body)
53
54 //去除STYLE
55 re, _ := regexp.Compile(`\<style[\S\s]+?\</style\>`)
56 bodyString = re.ReplaceAllString(bodyString, "")
57
58 //去除SCRIPT
59 re, _ = regexp.Compile(`\<script[\S\s]+?\</script\>`)
60 bodyString = re.ReplaceAllString(bodyString, "")
61
62 //去除连续的换行符
63 re, _ = regexp.Compile(`\s{2,}`)
64 bodyString = re.ReplaceAllString(bodyString, "")
65 // fmt.Println(bodyString)
66
67 re = regexp.MustCompile(`<a href="(.*?)" target="_blank">(.*?)</a>.*?<img src="" style="vertical-align: top;margin-top: 2px;"></div><small class="card-subtitle text-muted">.*?<span class="badge badge-tag">.*?</span></small>`)
68 result := re.FindAllStringSubmatch(strings.TrimSpace(bodyString), -1)
69 // fmt.Println(result)
70
71 var resultSlice [][]string
72 fmt.Printf("[*] [EdgeForum] crawler result:\n%s\n\n", utils.CurrentTime())
73 for _, match := range result {
74 fmt.Printf("%s\n", match[1:][1])
75 fmt.Printf("%s\n\n", match[1:][0])
76 resultSlice = append(resultSlice, match[1:])
77 }
78 if len(resultSlice) == 0 {
79 return nil, errors.New("no records in the last 24 hours")
80 }
81 return resultSlice, nil

Callers

nothing calls this directly

Calls 2

CrawlerClientFunction · 0.92
CurrentTimeFunction · 0.92

Tested by

no test coverage detected