我使用HtmlAgilityPack从远程html获取js脚本,如下所示;
...
string JsVars = _HtmlDocument.DocumentNode.SelectSingleNode("//script[contains(text(), 'blablaa')]").InnerText
JsVars返回如下;
var js_var1 = "blablaa";
var js_var2 = "hops";
无论如何,在用侏罗纪Evulate jsVars之后获得 js_var1 或 js_var2 值的价值?
var engine = new Jurassic.ScriptEngine();
var result = engine.Evaluate(_JsVars);
答案 0 :(得分:1)
您可以尝试这种方式:
var engine = new Jurassic.ScriptEngine();
var result = engine.Evaluate(_JsVars);
var var1 = engine.GetGlobalValue<string>("js_var1");
var var2 = engine.GetGlobalValue<string>("js_var2");
<强> [.NET fiddle demo] 强>
参考:Jurassic Documentation - Accessing and modifying global variables