gocolly / colly

Elegant Scraper and Crawler Framework for Golang
https://go-colly.org/
Apache License 2.0
23.16k stars 1.76k forks source link

SIGSEG on local files #768

Closed mlunax closed 1 year ago

mlunax commented 1 year ago

My code:

package main

import (
    "net/http"
    "os"

    "github.com/gocolly/colly/v2"
)

func main() {
    dir, err := os.Getwd()
    if err != nil {
        panic(err)
    }
    t := &http.Transport{}
    t.RegisterProtocol("file", http.NewFileTransport(http.Dir(os.Args[0])))

    c := colly.NewCollector()
    c.WithTransport(t)

    c.OnXML("PRODUCTDATA", func(element *colly.XMLElement) {
        println(element)
    })

    path := "file://" + dir + "/cat.xml"
    println(path)
    c.Visit(path)
    c.Wait()
    println(err.Error())
}

go.mod:

module main

go 1.14

require github.com/gocolly/colly/v2 v2.1.1-0.20230517145056-ea4b1dd0e5e6 // indirect

error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x894677]

goroutine 1 [running]:
main.main()
        /tmp/main.go:30 +0x1bc
exit status 2
WGH- commented 1 year ago

Could you please do some debugging before wasting other's time?