Goquery选择meta [property = og:image]?

时间:2015-05-04 06:12:07

标签: go goquery

Goquery Syntax-wise, it is as close as possible to jQuery, with the same function names when possible, and that warm and fuzzy chainable interface.

doc.Find("meta[property='og:image']").Each(func(i int, s *goquery.Selection) {
    fmt.Fprintln("og data=", s)
})

显然与j-thing不够接近。

如何从goquery获取网页中的og数据?

1 个答案:

答案 0 :(得分:3)

想出来 - 希望这有助于其他人

doc.Find("meta").Each(func(i int, s *goquery.Selection) {
    op, _ := s.Attr("property")
    con, _ := s.Attr("content")
    if op == "og:image" {
        fmt.Fprintln("og data=", con)
    }

})