Webbrowser control: Get element value and store it into a variable

后端 未结 1 2004
忘了有多久
忘了有多久 2020-12-06 09:03

Winform: Web browser Control

The web browser has the following displayed content, within a html table.

[Element]   [Value]
Name              


        
相关标签:
1条回答
  • 2020-12-06 09:37

    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);
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题