First
This commit is contained in:
41
main.go
Normal file
41
main.go
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user