This commit is contained in:
2022-10-20 10:03:56 -04:00
commit 71aaecb846
3 changed files with 177 additions and 0 deletions

41
main.go Normal file
View File

@@ -0,0 +1,41 @@
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))
}