Web浏览器控件:获取元素值并将其存储到变量中
Winform: Web浏览器控件
Web浏览器在html表中具有以下显示内容。
[Element] [Value] Name John Smith Email jsmith@hotmail.com
对于上面的示例,html代码可能看起来像这样
John Smith jsmith@hotmail.com
。
我想获取元素值,标签右侧的值。
做这个的最好方式是什么?
(我可以使用DOM还是需要使用正则表达式对html代码进行分阶段?)。
实现这一目标的方法不止一种。
例如,这对你有用吗?
using System.Windows.Forms; namespace TestWebBrowser { public partial class Form1 : Form { public Form1() { InitializeComponent(); webBrowser1.DocumentText = @" John Smith jsmith@hotmail.com
"; } private void button1_Click(object sender, System.EventArgs e) { HtmlElement e1 = webBrowser1.Document.GetElementById("e1"); MessageBox.Show(e1.InnerText); } } }