When I use colly, I have a case to to iterate context elements when I put something in it with multiple OnHTML callback on different html elements.
This is the simple function I wrote.
// ForEach iterate context
func (c *Context) ForEach(fn func(k string, v interface{}) interface{}) []interface{} {
c.lock.RLock()
defer c.lock.RUnlock()
ret := make([]interface{}, 0, len(c.contextMap))
for k, v := range c.contextMap {
cur := fn(k, v)
ret = append(ret, cur)
}
return ret
}
Hope this can help someone when they also need to iterate context.
When I use colly, I have a case to to iterate context elements when I put something in it with multiple
OnHTML
callback on different html elements. This is the simple function I wrote.Hope this can help someone when they also need to iterate context.