C # Web page to get the HTML parsing JS variables is a browser interaction (EvaluateScriptAsync), a parsing is HtmlAgilityPack

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/chenxiaotao22/article/details/78656830
            //获得天气预报获得observe24h_data变量
            //与下面方法结果相同,HtmlAgilityPack解析。
            var task1 = control.Browser.GetSourceAsync();
            task1.Wait();
            var htmlSource = task1.Result;
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(htmlSource);
            var a = doc.DocumentNode.SelectSingleNode("//script[contains(text(), 'observe24h_data')]").InnerHtml.Split(';')[0];

            //浏览器交互
            var task = control.Browser.EvaluateScriptAsync(@"observe24h_data");
            task.Wait();

Guess you like

Origin blog.csdn.net/chenxiaotao22/article/details/78656830