anaskhan96 / soup

Web Scraper in Go, similar to BeautifulSoup
MIT License
2.18k stars 168 forks source link

fix nil pointer dereference panic error #19

Closed bigzhu closed 6 years ago

bigzhu commented 6 years ago

my code like this

    scripts := doc.FindAll("script", "type", "text/javascript")
    for _, script := range scripts {
        scriptContent = script.Text()
                ...

script.Text() will cause golang panic when <script type="text/javascript" src="/static/bundles/base/zh_CN.js/fa1a0abb4687.js" crossorigin="anonymous"></script> in html   maybe need check k is nil at first

anaskhan96 commented 6 years ago

Thanks for the PR! I should probably clean up that function, what with all the gotos and unnecessary checks here and there.