2 回答
TA贡献1788条经验 获得超4个赞
//Set the options for download file through puppeteer
var options = new LaunchOptions
{
Headless = false,
ExecutablePath = "Path Of Browser to execute, example c://....edge.exe ", //
DefaultViewport = null,
Args = new[] { "--no-sandbox", "--start-maximized" },
};//Launch puppeteer for scrap the Document Data
using (var browser = await Puppeteer.LaunchAsync(options))
using (var page = await browser.NewPageAsync())
{
await page.Target.CreateCDPSessionAsync().Result.SendAsync("Page.setDownloadBehavior", new
{
behavior = "allow",
downloadPath = directoryToSave
}, false);
await page.AuthenticateAsync(new Credentials
{
Username = WindowsCredentials.Username,
Password = WindowsCredentials.Password
});
await page.GoToAsync("URL of file to download");
TA贡献1799条经验 获得超6个赞
我发现在现代版本的 Chrome 中无法执行此操作,因为 Page.setDownloadBehavior 已从 CDP v1.3 中删除https://chromedevtools.github.io/devtools-protocol /1-3.
更新: 这项工作https://gist.github.com/vabka/88a9b054ee756a53a44691366b16b474
- 2 回答
- 0 关注
- 225 浏览
添加回答
举报