是否可以使用js变量来使用Jurassic Library分配c#字符串

时间:2014-10-19 11:52:00

标签: javascript c# html-agility-pack jurassic

我使用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);

1 个答案:

答案 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