现在要做个winform获取网页中textbox控件的值来初始化启动界面。网页的源文件是这个
<input type="text" class=genFont name="system_hostname" size="30" maxlength="30" value="MegaPixelCamera">我要获取system_hostname中的value值,MegaPixelCamera这个是变量,要从数据库中获取。我的代码是这样
webBrowser1.Navigate("http://10.10.10.10/lang1/server_sys.html"); // url加载 if (webBrowser1.Document != null)
{
HtmlElement txtSearch = webBrowser1.Document.All["system_hostname"]; if (txtSearch != null)
{
// MessageBox.Show(txtSearch.GetAttribute("value")); //这个是值是MegaPixelCamera没错
MessageBox.Show(txtSearch.InnerText); //这个为空值
} }
另外,http://10.10.10.10/lang1/server_sys.html界面加载貌似有问题。提示window.parent.retframe.document为空或不是对象。我保存数据也是通过权限保存在这个界面上,保存可以,就是加载不行。 迫切希望有人给我解答,取得system_hostname.Value。谢谢。
<input type="text" class=genFont name="system_hostname" size="30" maxlength="30" value="MegaPixelCamera">我要获取system_hostname中的value值,MegaPixelCamera这个是变量,要从数据库中获取。我的代码是这样
webBrowser1.Navigate("http://10.10.10.10/lang1/server_sys.html"); // url加载 if (webBrowser1.Document != null)
{
HtmlElement txtSearch = webBrowser1.Document.All["system_hostname"]; if (txtSearch != null)
{
// MessageBox.Show(txtSearch.GetAttribute("value")); //这个是值是MegaPixelCamera没错
MessageBox.Show(txtSearch.InnerText); //这个为空值
} }
另外,http://10.10.10.10/lang1/server_sys.html界面加载貌似有问题。提示window.parent.retframe.document为空或不是对象。我保存数据也是通过权限保存在这个界面上,保存可以,就是加载不行。 迫切希望有人给我解答,取得system_hostname.Value。谢谢。
1,你不是已经取到值了吗?通过这个方法txtSearch.GetAttribute("value")2,除了这行webBrowser1.Navigate("http://10.10.10.10/lang1/server_sys.html"); // url加载
其他代码应该在webBrowser.Competed里面写,判断页面加载完了再获取其中txtSearch.InnerText值,
<input type="text" class=genFont name="system_hostname" size="30" maxlength="30" value="MegaPixelCamera"> 这个标记的InnerTxt本来就是什么都没有的
3,webBrowser1.Navigate(new Uri("http://10.10.10.10/lang1/server_sys.html"))
强制转换下,有时候,地址太长它就无法解析成链接。