Web scraping 如何在colly上启用Js
我有很多经验,但在这个项目中,我应该使用的一些原因。我正试图从网站上抓取数据,但它返回要重新获得访问权限,请确保在重新加载页面之前启用了cookies和JavaScript。 我的代码部分如下所示:Web scraping 如何在colly上启用Js,web-scraping,go-colly,Web Scraping,Go Colly,我有很多经验,但在这个项目中,我应该使用的一些原因。我正试图从网站上抓取数据,但它返回要重新获得访问权限,请确保在重新加载页面之前启用了cookies和JavaScript。 我的代码部分如下所示: func crawl(search savedSearch) { c := colly.NewCollector() extensions.RandomUserAgent(c) /* for debugging to see what is the result c.
func crawl(search savedSearch) {
c := colly.NewCollector()
extensions.RandomUserAgent(c)
/* for debugging to see what is the result
c.OnHTML("*", func(e *colly.HTMLElement) {
fmt.Println(e.Text)
os.Exit(1)
})*/
c.OnHTML(".result-list__listing", func(e *colly.HTMLElement) {
listingId, _ := strconv.Atoi(e.Attr("data-id"))
if !listingExist(search.id, listingId) {
fmt.Println("Listing found " + strconv.Itoa(listingId))
saveListing(search.id, listingId)
notifyUser(search.user, listingId)
}else{
fmt.Println("item is already crawled")
}
})
我在文档“自动cookie和会话处理”中看到,问题可能是js,我如何克服这个问题?首先,试一试如何在colly中启用js?colly是HTML页面的最佳选择。如果需要刮除JS驱动的页面,则需要使用不同的策略。浏览器有一个共同的协议来处理JS,它们有不同的库来处理不同的语言,包括Go