Monday, July 23, 2018

NOTES for js in C#

 


 

https://stackoverflow.com/questions/49015061/anglesharp-run-all-javascript-before-looking-for-element

var config = AngleSharp.Configuration.Default.WithDefaultLoader().WithCookies().WithJavaScript().WithCss();
            var browsingContext = BrowsingContext.New(config);

            await browsingContext.OpenAsync("https://users.premierleague.com/");
            await browsingContext.Active.QuerySelector("form[action='/accounts/login/']").SubmitAsync(new
            {
                login = "abc@gmail.com",
                password = "password"
            });
            await browsingContext.OpenAsync("https://fantasy.premierleague.com/a/team/my/");
   
foreach (var element in elements)
            {
                var scripts = element.GetElementsByTagName("script");
                
                foreach(var script in scripts)
                {
                    script.Parent.RemoveChild(script);
                }
            }
https://stackoverflow.com/questions/18156795/parsing-html-to-get-script-variable-value/18157325#18157325
var html = @"
             // Some HTML
             
             // More HTML
             ";

// Grab the content of the first script element
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
var script = doc.DocumentNode.Descendants()
                             .Where(n => n.Name == "script")
                             .First().InnerText;

// Return the data of spect and stringify it into a proper JSON object
var engine = new Jurassic.ScriptEngine();
var result = engine.Evaluate("(function() { " + script + " return spect; })()");
var json = JSONObject.Stringify(engine, result);

Console.WriteLine(json);
Console.ReadKey();
Output:
https://github.com/paulbartrum/jurassic
http://html-agility-pack.net/

https://stackoverflow.com/questions/20930414/how-to-dynamically-generate-html-code-using-nets-webbrowser-or-mshtml-htmldocu/20934538#20934538

https://stackoverflow.com/questions/21697048/how-to-fix-a-opacity-bug-with-drawtobitmap-on-webbrowser-control/21828265#21828265