QA.Firefox.FirefoxOptions ffOptions = new QA.Firefox.FirefoxOptions();
string tmpPath =@"D:\xiangcai";
if (!System.IO.Directory.Exists(tmpPath))
{
System.IO.DirectoryInfo d = System.IO.Directory.CreateDirectory(tmpPath);
}
var files = new System.IO.DirectoryInfo(tmpPath).GetFiles();
foreach(var item in files)
{
File.Delete(Path.GetFullPath(item.FullName));
}
#设置下载存储方式,2为自定义路径、设置成 0 表示下载到桌面;设置成 1 表示下载到默认路径
ffOptions.SetPreference("browser.download.folderList", 2);
#设置下载路径
ffOptions.SetPreference("browser.download.dir", tmpPath);
#对所给出文件类型不再弹出框进行询问
#ffOptions.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/ms-excel
C# 爬虫使用Selenium webDriver下载excel文件
于 2021-05-10 15:11:16 首次发布