golang pars div value
<body class="widget_frame_base tgme_widget body_widget_post emoji_image tme_mode nodark">
<div class="tgme_widget_message js-widget_message" data-post="hgfdhfghdfghf/2" data-view="eyJjIjotMTMzNjk4ODQ1MywicCI6MiwidCI6MTY0NzE4MzA3MCwiaCI6IjhiN2I4NDYxN2Y3YmU4ZTE3MCJ9" data-peer="c1336988453_-7513109051546167773" data-peer-hash="6af202fa41cc909675" data-post-id="2">
Как спарсить data-view? Использую "github.com/PuerkitoBio/goquery" ничего не получается.
Ответы (1 шт):
Автор решения: dikey0ficial
→ Ссылка
на основе кода из readme библиотеки и godoc'а:
// doc, err := goquery.NewDocumentFromReader(resp.Body)
var value string
query := doc.Find(".tgme_widget_message .js-widget_message").Each(func(i int, s *goquery.Selection) {
if value != "" { return } // мы будем находить только один value
if s == nil {
return
}
node := s.Get(0)
if node == nil || node.Attr == nil || len(node.Attr) == 0 {
return
}
for _, attr := range node.Attr {
if attr.Key == "data-view" {
value = attr.Val
return
}
}
})