2 回答

TA貢獻(xiàn)1788條經(jīng)驗(yàn) 獲得超4個(gè)贊
//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貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超6個(gè)贊
我發(fā)現(xiàn)在現(xiàn)代版本的 Chrome 中無(wú)法執(zhí)行此操作,因?yàn)?Page.setDownloadBehavior 已從 CDP v1.3 中刪除https://chromedevtools.github.io/devtools-protocol /1-3.
更新: 這項(xiàng)工作https://gist.github.com/vabka/88a9b054ee756a53a44691366b16b474
- 2 回答
- 0 關(guān)注
- 350 瀏覽
添加回答
舉報(bào)