为了账号安全,请及时绑定邮箱和手机立即绑定

ajax 加载网站内容后进行网页抓取

ajax 加载网站内容后进行网页抓取

Go
Qyouu 2023-07-04 15:04:56
这是我的代码:package mainimport (    "fmt"    "log"    "github.com/gocolly/colly")func main() {    c := colly.NewCollector(        colly.IgnoreRobotsTxt(),        colly.Async(false),    )    c.OnHTML("html", func(e *colly.HTMLElement) {        fmt.Println(e.Text)    })    c.OnError(func(_ *colly.Response, err error) {        log.Println("Something went wrong:", err)    })    c.Visit("https://www56.muenchen.de/termin/index.php?loc=BB")    c.OnScraped(func(r *colly.Response) {        fmt.Println("Finished")    })}问题是访问网站后它会加载一些内容。我不确定如何告诉 colly“等待”直到发生这种情况,然后查看结果。期待一些想法。去网络抓取
查看完整描述

1 回答

?
慕桂英3389331

TA贡献2036条经验 获得超8个赞

它不能,因为 colly 必须在客户端执行该操作,但 colly不执行 JavaScript - 因此没有 Ajax。

要模拟浏览器,您可以使用 selenium 或 phantomjs。


查看完整回答
反对 回复 2023-07-04
  • 1 回答
  • 0 关注
  • 52 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信