So I'm trying to get the ingredients for a recipe (trying goquery, used colly before to no success either). The HTML is the following way:
<div class="recipe-ingredients">
<ul>
<li>1 ½ lb chicken breast tenders</li>
<li><strong>Marinade</strong>
<ul>
<li>1 egg</li>
<li>1 tablespoon smoked paprika</li>
<li>2 teaspoons garlic powder</li>
<li>2 teaspoons onion powder</li>
<li>Pinch of sea salt & pepper</li>
<li>1 tablespoon maple syrup</li>
</ul>
</li>
<li>1 tablespoon arrowroot (or corn starch)</li>
<li>1 ½ cups corn flakes (crushed)</li>
</ul>
</div>
This is what I have right now:
doc.Find(".recipe-ingredients").Each(func(i int, selection *goquery.Selection) {
//selection.Find("ul").First().
})
As it shows, the second ingredient Marinade has sub-ingredients. I'd like to store these ingredients on the side. As in:
{
Name: Marinade,
Ingredients: ["1 egg", "1 tablespoon...", ...]
}
{
Name: MainRecipe
Ingredients: ["1 ½ lb chicken...",...]
}
When I was trying with colly, here I would now use selection and search the li elements, but I couldn't find a way to just search the first layer of children, so I would have to run over all of the elements.
Is there a way for me to tell it to search all the li elements that aren't inside another li element?