42 lines
796 B
Go
42 lines
796 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/gocolly/colly/v2"
|
|
)
|
|
|
|
type Kayak struct {
|
|
description string
|
|
price float64
|
|
url string
|
|
datetime time.Time
|
|
}
|
|
|
|
func main() {
|
|
layout := "2006-01-02 15:04"
|
|
c := colly.NewCollector()
|
|
|
|
kayaks := []Kayak{}
|
|
c.OnHTML(".result-info", func(e *colly.HTMLElement) {
|
|
kayak := Kayak{}
|
|
|
|
kayak.description = e.ChildText(".result-title")
|
|
kayak.url = e.ChildAttr(".result-title", "href")
|
|
t, err := time.Parse(layout, e.ChildAttr(".result-date", "datetime"))
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
kayak.datetime = t
|
|
kayaks = append(kayaks, kayak)
|
|
})
|
|
|
|
c.OnRequest(func(r *colly.Request) {
|
|
fmt.Println("Visiting", r.URL)
|
|
})
|
|
|
|
c.Visit("https://wilmington.craigslist.org/search/sss?query=kayak")
|
|
fmt.Println(len(kayaks))
|
|
}
|