全局变量名为 param1 var param1Value = webBrowser1.Document.InvokeScript(eval,new String[]{ param1}).To...
通過 WebBrowser 可以在頁面中執行 js 函數,與取得 js 變量值還是有一定距離,考慮到既然可以獲取頁面元素,為什么不通過頁面元素曲線救國呢?馬上行動。
?? 1? 用萬能的 eval 自定義一個函數,用來完成需要的操作
? 2 再用 eval 調用定義的函數傳入特定的參數:
public static string htmlid = Guid.NewGuid().ToString();
private string GetJsVar(WebBrowser webBrowser1, string varname)
{
if (webBrowser1.Document == null)
return "No document";
webBrowser1.Document.InvokeScript("eval", new[]{ @"
CreateHiddenInputForReturn = function(id, val) {
var elm = document.getElementById(id);
if(elm == null) {
elm = document.createElement('INPUT');
elm.id = id;
elm.type=""HIDDEN"";
document.body.insertBefore(elm);
}
elm.value = eval('typeof('+val.split(/[\[\.]/)[0]+')')=='undefined' ? id : eval(val);
}
"});
webBrowser1.Document.InvokeScript("CreateHiddenInputForReturn", new[] { htmlid, varname });
HtmlElement obj = webBrowser1.Document.GetElementById(htmlid);
if (obj != null)
{
string val = obj.GetAttribute("value");
if (val == htmlid)
return "no js var";
return val;
}
return "null";
}
總結
以上是生活随笔為你收集整理的全局变量名为 param1 var param1Value = webBrowser1.Document.InvokeScript(eval,new String[]{ param1}).To...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 抖音幕后老板是黄光裕吗 两者没有关系但或
- 下一篇: 支付宝芝麻信用几号更新 提升时注意这几