How to scrape an unordered list with go-colly?

Viewed 219

I am trying to build a personal scraper of food recipes. I am able to get all other elements but food ingredients that are in unordered list. Here is a snippet of the page html: pagehtml

My code so far that doesn't find strong element but prints "Ingredients found."

    collectorDish.OnHTML(".ingredients", func(element *colly.HTMLElement) {
        fmt.Println("Ingredients found")
        element.ForEach("li", func(_ int, el *colly.HTMLElement) {
            fmt.Println(el.ChildText("strong"))
            el.ForEach("strong", func(_ int, elem *colly.HTMLElement) {
                fmt.Println(elem.Text)
            })
        })
    })

I have tried different ways to get these elements but no luck so far. I noticed that there is a difference of data when inspecting the page html. Under "Inspect -> elements" the html is as shown on the image, but in "Inspect->Source->pagename" the html stands:

<ul class="ingredients">
                <div class="ellipsis">
                    <div></div>
                    <div></div>
                    <div></div>
                    <div></div>

So is the reason why I don't receive ingredients in my code or the way page is built? I am a complete noobie and don't understand why html looks different in elements vs source. Looking for anykind of clues to get it working. Thanks and all the best!

0 Answers
Related