1package main 2 3import ( 4 "fmt" 5 "strings" 6 7 "github.com/antchfx/xquery/html" 8) 9 10func main() { 11 u := "https://www.amazon.com/Microsoft-Surface-Pro-QG2-00001-4300U/dp/B00NVXE45U" 12 doc, err := htmlquery.LoadURL(u) 13 if err != nil { 14 panic(err) 15 } 16 var product struct { 17 name string 18 price string 19 brand string 20 merchant string 21 } 22 product.name = htmlquery.InnerText(htmlquery.FindOne(doc, "//span[@id='productTitle']")) 23 product.brand = htmlquery.InnerText(htmlquery.FindOne(doc, "//a[@id='brand']")) 24 product.price = htmlquery.InnerText(htmlquery.FindOne(doc, "//span[@id='priceblock_ourprice']")) 25 product.merchant = htmlquery.InnerText(htmlquery.FindOne(doc, "//div[@id='merchant-info']/a")) 26 27 fmt.Printf("%s \n", u) 28 fmt.Printf("Name: %s\n", strings.TrimSpace(product.name)) 29 fmt.Printf("Brand: %s\n", product.brand) 30 fmt.Printf("Price: %s\n", product.price) 31 fmt.Printf("Merchant: %s\n", product.merchant) 32} 33