【问题标题】:c# windows form - How received a tag value data into my textbox1?c# windows form - 如何将标签值数据接收到我的textbox1中?
【发布时间】:2015-08-26 13:50:57
【问题描述】:
<input name="chkFile" value="2062223616_7147073260_1440589192619132.WMA" type="checkbox">

从此代码中我只想要值数据

例子:

2062223616_7147073260_1440589192619132.WMA

下面我的代码不起作用所以请帮助我。

我的代码

HtmlElementCollection bColl = webBrowser2.Document.GetElementsByTagName("input");
            foreach (HtmlElement bEl in bColl)
            {
                if (bEl.GetAttribute("name").Equals("chkFile"))
                    showaudiourl.Text = bEl.OuterHtml.Split('"')[3];
            }

【问题讨论】:

  • 我是新来的,所以请给我有关正则表达式解决方案的详细信息。
  • 请编写完整代码并展示给我看,然后我将其放入我的编码中并尝试。我是新人,所以请给我完整的细节。

标签: regex split streamreader htmlelements


【解决方案1】:

使用 webBrowser2.GetAttribute("value") 获得您想要的价值。

HtmlElementCollection bColl = webBrowser2.Document.GetElementsByTagName("input");
foreach (HtmlElement bEl in bColl) {
    if (bEl.GetAttribute("name").Equals("chkFile")) {
        showaudiourl.Text = bEl.GetAttribute("value");    //Changes here
    }
}

【讨论】:

    【解决方案2】:

    您只需要添加一段代码,告诉应用等待网络浏览器文档被初始化:

    webBrowser2.Navigate(@"C:\tmp.html");                        // Use your own URL here
    while (webBrowser2.ReadyState != WebBrowserReadyState.Complete) // Without it, 
       Application.DoEvents();                                // the document will be null
    
    HtmlElementCollection bColl = webBrowser2.Document.GetElementsByTagName("input");
    foreach (HtmlElement bEl in bColl)
    {
       if (bEl.GetAttribute("name").Equals("chkFile"))
          showaudiourl.Text = bEl.GetAttribute("value");
    }
    

    应使用bEl.GetAttribute("value") 访问该值。

    或者,您可以使用webBrowser2_DocumentCompleted 事件在此处处理 HTML 文档。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多