WebBrowser控件:获取元素值,并将其存储到一个变量 [英] Webbrowser control: Get element value and store it into a variable
本文介绍了WebBrowser控件:获取元素值,并将其存储到一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Winform的: Web浏览器控件
Web浏览器具有以下显示的内容,一个HTML表中。
The web browser has the following displayed content, within a html table.
[Element] [Value]
Name John Smith
Email jsmith@hotmail.com
对于上面的例子中,HTML code,可能是这个样子
For the example above, the html code, might look something like this
<table>
<tbody>
<tr>
<td><label class="label">Name</label></td>
<td class="normaltext">John Smith</td>
</tr>
<tr> <td><label class="label">Email</label></td>
<td><span class="normaltext">jsmith@hotmail.com</span></td>
</tr>
</tr>
</tbody>
</table>
我想要得到的元素值,该值在标签的右侧。
什么是做到这一点的最好方法是什么?
(我可以使用DOM或者我需要逐步的HTML code。与常规的前pression?)
(Can I use DOM or do I need to phase the html code with a regular expression?) .
推荐答案
有是不止一种方法更做到这一点。
there're more than one way to accomplish this.
例如,将这项工作的吗?
For instance, will this work for you?
using System.Windows.Forms;
namespace TestWebBrowser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.DocumentText = @"<html><body><table>
<tbody>
<tr>
<td><label class=""label"">Name</label></td>
<td class=""normaltext"">John Smith</td>
</tr>
<tr> <td><label class=""label"">Email</label></td>
<td><span class=""normaltext"" id=""e1"">jsmith@hotmail.com</span></td>
</tr>
</tr>
</tbody>
</table>
</body>
</html>";
}
private void button1_Click(object sender, System.EventArgs e)
{
HtmlElement e1 = webBrowser1.Document.GetElementById("e1");
MessageBox.Show(e1.InnerText);
}
}
}
这篇关于WebBrowser控件:获取元素值,并将其存储到一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文