Skip to content

Instantly share code, notes, and snippets.

@buildingwatsize
Created July 16, 2020 07:08
Show Gist options
  • Save buildingwatsize/9e3873f09ac365a51d53276b97ecf3c9 to your computer and use it in GitHub Desktop.
Save buildingwatsize/9e3873f09ac365a51d53276b97ecf3c9 to your computer and use it in GitHub Desktop.
Core Code for Harvesting Data from ทองคำราคา.com via Colly
...
c := colly.NewCollector()
c.OnHTML(GoldtradersTableElement, func(e *colly.HTMLElement) {
barSell = e.ChildText("tr:nth-child(2) > td:nth-child(2)")
barBuy = e.ChildText("tr:nth-child(2) > td:nth-child(3)")
ornamentSell = e.ChildText("tr:nth-child(3) > td:nth-child(2)")
ornamentBuy = e.ChildText("tr:nth-child(3) > td:nth-child(3)")
statusChange = e.ChildAttr("tr:nth-child(4) > td.span > .imgp", "alt")
todayChange = strings.Split(e.ChildText("tr:nth-child(4) > td:nth-child(1)"), " ")[1]
updatedDate = e.ChildText("tr:nth-child(5) > td.span.bg-span.txtd.al-r")
updatedTime = e.ChildText("tr:nth-child(5) > td.em.bg-span.txtd.al-r")
})
c.Visit(GoldtradersLink)
log.Println("ทองแท่ง ขายออก:", barSell)
log.Println("ทองแท่ง รับซื้อ:", barBuy)
log.Println("ทองรูปพรรณ ขายออก:", ornamentSell)
log.Println("ทองรูปพรรณ รับซื้อ:", ornamentBuy)
log.Println("สถานะ:", statusChange)
log.Println("เปลี่ยนแปลงวันนี้:", todayChange)
log.Println("วันที่อัพเดท:", updatedDate)
log.Println("เวลาที่อัพเดท:", updatedTime)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment