using OpenQA.Selenium;using OpenQA.Selenium.Edge;using System;using System.Threading;class Program{static void Main(string[] args){// 初始化 Edge 浏览器var options = new EdgeOptions();options.AddArgument("--user-data-dir=C:\\Users\\qctol\\AppData\\Local\\Microsoft\\Edge\\User Data"); // 指定用户数据目录options.AddUserProfilePreference("download.default_directory", @"E:\Project\EdgeCollection");// 初始化 Edge 浏览器IWebDriver driver = new EdgeDriver(options);try{// 打开 Edge 浏览器中的集锦页面driver.Navigate().GoToUrl("edge://collections");// 等待页面加载Thread.Sleep(5000);// 获取所有集锦var collections = driver.FindElements(By.ClassName("collection-name"));foreach (var collection in collections){string collectionName = collection.Text;Console.WriteLine($"处理集锦: {collectionName}");// 点击集锦collection.Click();Thread.Sleep(2000);// 点击更多操作driver.FindElement(By.XPath("//button[@aria-label='更多操作']")).Click();Thread.Sleep(2000);// 选择导出driver.FindElement(By.XPath("//button[@aria-label='导出']")).Click();Thread.Sleep(2000);// 选择导出格式(例如 HTML)driver.FindElement(By.XPath("//button[@aria-label='HTML']")).Click();Thread.Sleep(2000);// 保存文件// 这里假设你已经配置了下载路径Thread.Sleep(5000);}}catch (Exception ex){Console.WriteLine($"发生错误: {ex.Message}");}finally{// 关闭浏览器driver.Quit();}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。