3

错误

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.

在此处输入图像描述

源代码

/// <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/");
4

1 回答 1

3

FirefoxProfile构造函数(字符串)使用特定的配置文件目录初始化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");

参考

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

于 2020-07-14T07:39:39.437 回答