簡體   English   中英

木偶操縱者鋒利的 NavigationException Firefox

[英]puppeteer-sharp NavigationException Firefox

請告訴我,當使用帶有 firefox 的選項“userdatadir”時,我無法導航到該頁面。該網站在瀏覽器中打開,但我在使用時遇到錯誤

等待頁面.GoToAsync

Browser browser = await Puppeteer.LaunchAsync(new LaunchOptions
        {
            Headless = false,
            ExecutablePath = "C:\\Program Files\\Mozilla Firefox\\firefox.exe",
            Product = Product.Firefox,
            UserDataDir = @"C:\Users\Nihao\AppData\Roaming\Mozilla\Firefox\Profiles\fp8f64bb.Mika",
            DefaultViewport = null,
            IgnoreHTTPSErrors = true,
            Args = new[] { "-wait-for-browser" }
        });
    
        Page page = await browser.NewPageAsync();
        await page.GoToAsync("https://whoer.net"); //exception here

例外

PuppeteerSharp.NavigationException:“超時超過 30000 毫秒”

使用超時 0 時出現異常

page.DefaultNavigationTimeout = 0;

PuppeteerSharp.NavigationException:“導航失敗,因為瀏覽器已斷開連接。PuppeteerSharp.FrameManager.d__42.MoveNext()

當我不使用“UserDataDir”(沒有配置文件)時,一切正常。 也許還有另一種方法,如何使用Firefox Profile?

使用以下對我有用的代碼:

            // Initiating Browser configuration
            Console.WriteLine("Intiating Browser");
 
             Browser browser = (Browser)await Puppeteer.LaunchAsync(new LaunchOptions
            {
                Headless = false,
                ExecutablePath = @"C:\Program Files\Mozilla Firefox\firefox.exe",
                Product = Product.Firefox,
                UserDataDir = @"C:\Users\Nihao\AppData\Roaming\Mozilla\Firefox\Profiles\fp8f64bb.Mika",
                DefaultViewport = null,
                IgnoreHTTPSErrors = true,
                Args = new[] { "-wait-for-browser" }
            });

                
            // Loading url.
            Console.WriteLine("Navigating to the URL");
            Page page3 =(Page)await browser.NewPageAsync();
            page3.DefaultNavigationTimeout = 0;
            await page3.GoToAsync("https://whoer.net");

            // Fetching content from the page.
            Console.WriteLine("Fetching content in the URL.");
            var content = await page3.GetContentAsync();
            
            Console.WriteLine("Content fetching completed! ");

            // Closing Browser
            Console.WriteLine("Closing browser.");
            await browser.CloseAsync();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM