gpt4 book ai didi

c# - 通过 GeckoDriver Selenium 和 C# 加载现有 FirefoxProfile 时, 'System.IO.Compression.ZipStorer' 的类型初始值设定项引发异常

转载 作者:行者123 更新时间:2023-12-04 14:12:58 25 4
gpt4 key购买 nike

错误

System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'System.IO.Compression.ZipStorer' threw an exception.
Source=WebDriver
StackTrace:
at System.IO.Compression.ZipStorer.WriteLocalHeader(ZipFileEntry& zipFileEntry)
at System.IO.Compression.ZipStorer.AddStream(CompressionMethod compressionMethod, Stream sourceStream, String fileNameInZip, DateTime modificationTimeStamp, String fileEntryComment)
at System.IO.Compression.ZipStorer.AddFile(CompressionMethod compressionMethod, String sourceFile, String fileNameInZip, String fileEntryComment)
at OpenQA.Selenium.Firefox.FirefoxProfile.ToBase64String()
at OpenQA.Selenium.Firefox.FirefoxOptions.GenerateFirefoxOptionsDictionary()
at OpenQA.Selenium.Firefox.FirefoxOptions.ToCapabilities()
at OpenQA.Selenium.Firefox.FirefoxDriver.ConvertOptionsToCapabilities(FirefoxOptions options)
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxOptions options)
at linkedin_mp.Controllers.LinkedInController.Get2() in E:\github\donhuvy\linkedin_crawler\Controllers\LinkedInController.cs:line 208
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

This exception was originally thrown at this call stack:
[External Code]

Inner Exception 1:
NotSupportedException: No data is available for encoding 437. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.

enter image description here

源代码

/// <summary>
/// Get a specific profile information.
/// URL: https://localhost:5001/linkedin/getprofile
/// </summary>
/// <returns>Danh sách các string là URL profile LinkedIn.</returns>
[HttpGet]
[Route("getprofile")]
public IEnumerable<string> Get2()
{
List<string> list = new List<string>();
Console.OutputEncoding = System.Text.Encoding.UTF8;
// Bắt buộc phải nạp Profile đang sử dụng.
// string PROFILE_DIR = "D://tmp//linkedin_tien";
FirefoxOptions firefoxOptions = new FirefoxOptions();
FirefoxProfile firefoxProfile = new FirefoxProfile("C:\\Users\\MinhPhuc\\AppData\\Local\\Mozilla\\Firefox\\Profiles\\tiqq1wks.dev-edition-default\\");
// FirefoxProfile firefoxProfile = new FirefoxProfile();
// firefoxProfile.SetPreference("permissions.default.image", 2);
// firefoxProfile.SetPreference("general.useragent.override", "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25");
firefoxProfile.DeleteAfterUse = false;
firefoxOptions.Profile = firefoxProfile;
// firefoxOptions.SetPreference("permissions.default.stylesheet", 2);
// firefoxOptions.SetPreference("javascript.enabled", false);
// firefoxOptions.SetPreference("dom.ipc.plugins.enabled.libflashplayer.so", false);
using IWebDriver driver = new FirefoxDriver(firefoxOptions);
// IWebDriver driver = new FirefoxDriver(firefoxOptions);
WebDriverWait webDriverWait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
driver.Navigate().GoToUrl("https://www.linkedin.com/");

最佳答案

FirefoxProfile Constructor (String)初始化 FirefoxProfile 的新实例使用特定的配置文件目录的类。

因此在使用 GeckoDriver 时和现有的FirefoxProfile()而不是:

FirefoxProfile firefoxProfile = new FirefoxProfile("C:\\Users\\MinhPhuc\\AppData\\Local\\Mozilla\\Firefox\\Profiles\\tiqq1wks.dev-edition-default\\");

您需要删除结尾的斜杠 \\,如下所示:

FirefoxProfile firefoxProfile = new FirefoxProfile("C:\\Users\\MinhPhuc\\AppData\\Local\\Mozilla\\Firefox\\Profiles\\tiqq1wks.dev-edition-default");

引用资料

您可以在以下位置找到一些相关的详细讨论:

关于c# - 通过 GeckoDriver Selenium 和 C# 加载现有 FirefoxProfile 时, 'System.IO.Compression.ZipStorer' 的类型初始值设定项引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62889822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com