chromedp下载文件的方法,备忘一下。

 

 1     sect := `//a[@href="v/443.json"]`
 2     wd,_ := os.Getwd()
 3     fmt.Println(wd)
 4     return chromedp.Tasks{
 5         //chromedp.Navigate(url),
 6         chromedp.WaitVisible(sect),
 7         page.SetDownloadBehavior(page.SetDownloadBehaviorBehaviorAllow).WithDownloadPath(wd),
 8         chromedp.Click(sect, chromedp.NodeVisible),
 9         chromedp.Sleep(3 * time.Second),
10     }

加入page.SetDownloadBehavior(page.SetDownloadBehaviorBehaviorAllow).WithDownloadPath(wd),

这句就可以下载文件了,不过chrome显示的情况下正常,如果chrome设置成headless的时候下载不正常,这个还需要进一步探索。

posted @ 2019-02-15 17:03  深夜  阅读(1892)  评论(0编辑  收藏  举报