救助!!!c#WINFORM怎样获取网页中变量的值??最好能给出一个具体实例!

来源:百度知道 编辑:UC知道 时间:2024/05/28 02:27:36
是网页源代码中JavaScript中变量的值,比如代码中有一个str这个变量 它代表的是一个数字比如20,我怎样获取str这个变量的值也就是20?或者有什么其他的方法

网页中的变量??是javascript中的变量吗?

用正则去匹配 比如去查找var Id 的值
C# code

Match m = Regex.Match(yourGetHTMLString,@"var\s+Id=\s*("")([^\1]*)\1",RegexOptions.IgnoreCase);

string id;
if(m.Success)
{
id = m.Groups[2].Value;
}

记得引入using System.Text.RegularExpressions;
没问题的,楼主试一下吧!!~~
如不明白HI~~~

<html>
<head>
<script>
function getValue()
{
var str = 20; //变量
document.getElementById("str").value = str; //把str的值赋予给input
} //onload加载页面调用取值方法
</script>
</head>
<body onload="getValue()">
<input type="text" id="str"/>
</body>
</html>

不知道你是不是这个意思