is it possible to get js variable to assignt c# string with using Jurrassic Library

998 views Asked by At

I am getting js script from remote html with using HtmlAgilityPack as below;

....

string JsVars = _HtmlDocument.DocumentNode.SelectSingleNode("//script[contains(text(), 'blablaa')]").InnerText

JsVars returns as below;

var js_var1 = "blablaa";
var js_var2 = "hops";

is there anyway to get value of js_var1 or js_var2 values after Evulate jsVars with Jurassic?

var engine = new Jurassic.ScriptEngine();
var result = engine.Evaluate(_JsVars);
1

There are 1 answers

0
har07 On BEST ANSWER

You can try this way :

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]

Reference : Jurassic Documentation - Accessing and modifying global variables