Basically, it’s like this:
x := "It worked earlyer lol"
go func(x string){
c.onHTML(...){
print(x)
}
c.visit(https://www.site.com)
}
so that’s the gist when I print the variables that are blank but outside of the go func they are defined here’s the full parent function:
eventCollector.OnHTML(".rgMasterTable tr", func(h *colly.HTMLElement) {
eventName := h.ChildText("td:nth-child(3) a")
eventURL := h.ChildAttr("td:nth-child(3) a", "href")
state := h.ChildText("td:nth-child(2)")
wgFR.Add(1) // Increment WaitGroup counter for each goroutine
semaphore <- struct{}{} // Acquire a token
go func(eventName, eventURL, state string) {
defer wgFR.Done() // Signal completion when the goroutine exits
defer func() { <-semaphore }()
contestCollector := eventCollector.Clone()
var postedDateStr string
contestCollector.OnHTML("#ctl00_ContentPlaceHolder1_FormView1_Report_2Label", func(d *colly.HTMLElement) {
postedDateStr = d.Text
})
contestCollector.OnHTML(".rgMasterTable tr", func(c *colly.HTMLElement) { // troubled line
contestName := c.ChildText("td:nth-child(1)")
contestURL := c.ChildAttr("td:nth-child(3) a", "href")
if contestURL == "" {
contestURL = "FORMAT-ERROR"
} // tmp handler for document style results
postedDate, timeErr := time.Parse("Jan 2, 2006", postedDateStr)
if timeErr != nil {
log.Printf("Error parsing time from %s", eventURL)
}
contest := Contest{
EventName: eventName,
ContestName: contestName,
PostedDate: postedDate,
ContestURL: contestURL,
State: state,
Present: true,
}
fResults = append(fResults, contest)
})
err := contestCollector.Visit("https://www.judgingcard.com/Results/" + eventURL)
if err != nil {
log.Printf("Could not find event: %s -- %s", eventURL, eventName)
}
contestCollector.Wait() // Wait for the inner collector to finish
}(eventName, eventURL, state)
})
in the full version all variables passed to the go func return blank if in the callback (contestCollector.OnHTML) unfortunately I’m not sure weather issue likes in the go routine, the fact that is as callback or whatever else.
Thanks in advance!