我有过很多使用刮痕的经验,但是在这个项目中,我应该使用柯利。我正在尝试从一个网站中刮取数据,但它返回以重新获得访问,请确保在重新加载页面之前启用了cookie和JavaScript。
我的代码部分如下:
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?
发布于 2021-02-19 09:15:55
Colly是HTML页面的最佳选择。如果您需要抓取JS驱动的页面,则需要使用不同的策略。浏览器在JS上有一个共同的协议,对于不同的语言有不同的库,包括Go。
https://stackoverflow.com/questions/64192184
复制相似问题