하고 있었다 몇몇 웹 긁어를 사용하여 colly 하지만 그것을 실행하고 싶었을 주기적으로 사용하 cron. 나는 시도는 기본적인 접근 방식이다.
type scraper struct {
coll *colly.Collector
rc *redis.Client
}
func newScraper(c *colly.Collector, rc *redis.Client) scraper {
return scraper{coll: c, rc: rc}
}
func main() {
rc := redis.NewClient(&redis.Options{
Addr: "localhost:3000",
Password: "", // no password set
DB: 0, // use default DB
})
coll := colly.NewCollector()
scrape := newScraper(coll, rc)
c := cron.New()
c.AddFunc("@every 10s", scrape.scrapePls)
c.Start()
sig := make(chan int)
<-sig
}
func (sc scraper) scrapePls() {
sc.coll.OnHTML(`body`, func(e *colly.HTMLElement) {
//Extracting required content
//Using Redis to store data
})
sc.coll.OnRequest(func(r *colly.Request) {
log.Println("Visting", r.URL)
})
sc.coll.Visit("www.example.com")
}
그것은 작동하지 않게 전화를 한 번지 않는 정기적으로 다음 호출합니다. 가 확실하지 않으면 나는 누락에 무언가이다. 은 다른 접근을 취할 수 있는?
어떤 도움을 감사하겠습니다.
감사합니다!
{1 {30s} 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC 0x6efa80 0x6efa80}]
. 이 유용하지 않습니다. 이 도움이 되나요?