var data MemberDetails

detailCollector.OnHTML("div.block-container div.block-body:first-of-type", 
func(h *colly.HTMLElement) { 
    selection := h.DOM 
    key := selection.Find("dl > dt").Text() 
    val := selection.Find("dl > dd").Text() 
    switch key {
        case "Full name": data.FullName = val
        case "Rank": data.Rank = val
        case "Primary position": data.PrimaryPosition = val
    }
})

fmt.Printf("data: %+v\n", data)

Enrique a következőt írta (2024. január 29., hétfő, 3:21:32 UTC+1):

> Hello, I am new to golang, and am working on a small web scrapper project, 
> where i crawl through a website for a guild that i'm associated with.
>
> Ideally I would like to pull the data from each 'dl' (html below) and 
> insert it into the MemberDetails Struct, however all attempts to parse the 
> below html result in the following string being returned
>
> Printout dt - 0: [Full nameRankPrimary position]
>
> Do you have any advice on how I could get one element at a time?
>
>    - Full Name
>    - John Doe
>
> Note: Library being used github.com/gocolly/colly
> <div class="block-container"> <h3 class="block-formSectionHeader">
> Information</h3> <div class="block-body block-row"> <dl class="pairs 
> pairs--columns rosters-rows"> <dt>Full name</dt> <dd>John Doe</dd> </dl> <
> dl class="pairs pairs--columns rosters-rows"> <dt>Rank</dt> <dd>Rank #1</
> dd> </dl> <dl class="pairs pairs--columns rosters-rows"> <dt>Primary 
> position</dt> <dd>General Staff</dd> </dl> </div>> </div> type 
> MemberDetails struct { FullName string Rank string PrimaryPosition string 
> } // ... detailCollector.OnHTML("div.block-container 
> div.block-body:first-of-type", func(h *colly.HTMLElement) { selection := 
> h.DOM val := selection.Find("dl > dt").Text() fmt.Printf("Printout dt - 
> 0: %s \n", val) }) 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/fd2dc57d-2b40-4d7b-a753-252a1cbc135bn%40googlegroups.com.

Reply via email to