Szanowni forumowicze. Mam problem z pobieraniem zawartości strony z CefSharpa. Gdy w chromie wejdę na 4programmers.net i wykonam kolejne skrypty JavaScript dostaję albo długi string, lub całego div'a wraz z dziećmi:

Kopiuj
document.querySelector("#entry-140680").querySelector(".microblog-text").innerText
Kopiuj
document.querySelector("#entry-140680").querySelector(".microblog-text")

screenshot-20240227085341.png

Natomiast gdy próbuje wykonać ten sam JS w CefSharp w przypadku tekstu dostaję go, natomiast w przypadku zwracania div'a dostaję null. Poniżej załączam kod C#, oraz wyjście (z pominięciem komunikatów samego CEF'a)

Kopiuj
        public static int Main(string[] args)
        {
#if ANYCPU
            //Only required for PlatformTarget of AnyCPU
            CefRuntime.SubscribeAnyCpuAssemblyResolver();
#endif

            const string testUrl = "4programmers.net";

            AsyncContext.Run(async delegate
            {
                var settings = new CefSettings()
                {
                    //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
                    CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache")
                };

                // Create the CefSharp.OffScreen.ChromiumWebBrowser instance
                using (var browser = new ChromiumWebBrowser(testUrl))
                {
                    var initialLoadResponse = await browser.WaitForInitialLoadAsync();

                    if (!initialLoadResponse.Success)
                    {
                        throw new Exception(string.Format("Page load failed with ErrorCode:{0}, HttpStatusCode:{1}", initialLoadResponse.ErrorCode, initialLoadResponse.HttpStatusCode));
                    }

                    //Give the browser a little time to render
                    await Task.Delay(10000);

                    await browser.EvaluateScriptAsync("window.scrollTo(0,800);");

                    await Task.Delay(10000);

                    await browser.EvaluateScriptAsync("document.querySelector(\"#entry-140680\").querySelector(\".microblog-text\").innerText").ContinueWith(x =>
                    {
                        var response = x.Result;

                        if (response.Success && response.Result != null)
                        {
                            Console.WriteLine(response.Result == null ? "NULL" : response.Result.ToString());
                        }
                    });

                    Console.WriteLine("--------------");

                    await browser.EvaluateScriptAsync("document.querySelector(\"#entry-140680\")").ContinueWith(x =>
                    {
                        var response = x.Result;

                        if (response.Success)
                        {
                            Console.WriteLine(response.Result == null?"NULL":response.Result.ToString());
                        }
                    });
                }

                Cef.Shutdown();
            });

            return 0;
        }

Natomiast wyjście to:

Kopiuj
Dziś kilka słów o konferencjach. W dużym skrócie. Jak chcecie Home Office, to zapomnijcie o starych dobrych konferencjach.

https://koziolekweb.pl/2024/02/22/home-office-a-sprawa-konferencji/

#koziolekweb #autopromocja
--------------
NULL

Jak mogę zwrócić całego DIV'a do kodu C# w postaci stringa, jsona, czegokolwiek?

Z góry dziękuję za pomoc i sugestie.