|
发表于 2021-12-10 20:32:36
|
显示全部楼层
go语言代码
- package toolsimport ( "strings" "utils")type NetcupMonitor struct{ KeyScanned map[string]bool}func (m* NetcupMonitor) Reset() { m.KeyScanned = make(map[string]bool)}func (m* NetcupMonitor) Scan() { c, err := utils.NewHttpClient("", "", "") if err != nil { return } threadUrl := "https://**cup-sonderangebote.de/" _, resp, err := utils.HttpGet(c, threadUrl) if resp != "" { offset := 0 for { title, pos := utils.StrMid(resp,`"card--content--title">`, "<", offset) if pos <= 0 || len(title) <= 0{ break } offset = pos ok := m.KeyScanned[title] if ok { continue } endPos := strings.Index(resp[offset:], "<a") if endPos > 0 { cacheLen := len(resp) - offset if cacheLen > 0x10 { cacheLen = 0x10 } hrefUrl := resp[offset + endPos: offset + endPos + cacheLen] if strings.Index(hrefUrl, "disabled") < 0 { m.KeyScanned[title] = true utils.Notify("netcup:" + title) } } } }}func NewNetcupMonitor() *NetcupMonitor { return &NetcupMonitor{ KeyScanned: make(map[string]bool), }}
复制代码 |
|