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");
ffOptions.SetPreference("browser.helperApps.neverAsk.saveToDisk", "ap
C# 爬虫使用Selenium webDriver下载excel文件
于 2021-05-10 15:11:16 首次发布
本文详细介绍了如何利用C#编程语言结合Selenium WebDriver,在火狐浏览器环境下,实现网页上Excel文件的自动下载。通过实例代码,演示了如何定位到文件下载链接并触发下载过程,为爬虫开发者提供了宝贵的经验。

最低0.47元/天 解锁文章
1131

被折叠的 条评论
为什么被折叠?



