Get 获取安全客前24小时内文章。
()
| 23 | |
| 24 | // Get 获取安全客前24小时内文章。 |
| 25 | func (crawler Anquanke) Get() ([][]string, error) { |
| 26 | client := utils.CrawlerClient() |
| 27 | |
| 28 | req, err := http.NewRequest("GET", "https://www.anquanke.com/knowledge", nil) |
| 29 | if err != nil { |
| 30 | return nil, err |
| 31 | } |
| 32 | |
| 33 | req.Header.Set("Cache-Control", "no-cache") |
| 34 | req.Header.Set("Upgrade-Insecure-Requests", "1") |
| 35 | 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") |
| 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("Sec-Fetch-Dest", "document") |
| 41 | req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9") |
| 42 | resp, err := client.Do(req) |
| 43 | if err != nil { |
| 44 | return nil, err |
| 45 | } |
| 46 | defer resp.Body.Close() |
| 47 | |
| 48 | body, err := ioutil.ReadAll(resp.Body) |
| 49 | if err != nil { |
| 50 | return nil, err |
| 51 | } |
| 52 | |
| 53 | bodyString := string(body) |
| 54 | |
| 55 | //去除STYLE |
| 56 | re, _ := regexp.Compile(`\<style[\S\s]+?\</style\>`) |
| 57 | bodyString = re.ReplaceAllString(bodyString, "") |
| 58 | |
| 59 | //去除SCRIPT |
| 60 | re, _ = regexp.Compile(`\<script[\S\s]+?\</script\>`) |
| 61 | bodyString = re.ReplaceAllString(bodyString, "") |
| 62 | |
| 63 | //去除head |
| 64 | re, _ = regexp.Compile(`\<head[\S\s]+?\</head\>`) |
| 65 | bodyString = re.ReplaceAllString(bodyString, "") |
| 66 | |
| 67 | //去除header |
| 68 | re, _ = regexp.Compile(`\<header[\S\s]+?\</header\>`) |
| 69 | bodyString = re.ReplaceAllString(bodyString, "") |
| 70 | |
| 71 | //去除footer |
| 72 | re, _ = regexp.Compile(`\<footer[\S\s]+?\</footer\>`) |
| 73 | bodyString = re.ReplaceAllString(bodyString, "") |
| 74 | |
| 75 | //去除sidebar |
| 76 | re, _ = regexp.Compile(`\<div class="load-more[\S\s]+?\</html\>`) |
| 77 | bodyString = re.ReplaceAllString(bodyString, "") |
| 78 | |
| 79 | //去除tag及desp |
| 80 | re, _ = regexp.Compile(`\<div class="tags hide-in-mobile-device[\S\s]+?class="fa fa-clock-o"\>`) |
| 81 | bodyString = re.ReplaceAllString(bodyString, "") |
| 82 |
nothing calls this directly
no test coverage detected