【问题标题】:How to save the value of a textbox defined in HTML file to a text file using Tagname如何使用标记名将 HTML 文件中定义的文本框的值保存到文本文件中
【发布时间】:2023-04-08 07:53:01
【问题描述】:

我想将 webbrowser 中显示的 textarea 的值保存在 txt 文件中 我想通过 GetelementbyTagName NOT GetelementbyID 来做到这一点 谢谢

【问题讨论】:

    标签: c# html webbrowser-control


    【解决方案1】:

    在您的网页完成后,请执行以下操作:(for multi textarea)

      private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("textarea "))
                {
                   if(el.GetAttribute("ClassName")=="classname")
                   {
                    File.WriteAllText("address of file", el.InnerText);
                   }
                }
            }
    

    已编辑:

    单身textarea:

     foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("textarea "))
                    {
                        File.WriteAllText("address of file", el.InnerText);
                    }
    

    【讨论】:

    • 谢谢,但我不知道为什么它不起作用我需要在按钮中定义它我需要写什么而不是 Classname?
    • 不知道您可以在按钮事件中编写它,您的网络浏览器控件中的文本区域如何?
    • 只有2个,我不知道怎么回事,但它仍然不起作用你知道吗?
    • @Pedram:如果你在 webbrowser 中有多个 textarea 为它们设置一个类名或 id.after 你可以简单地用它的 id 或类名获取他们的文本
    猜你喜欢
    • 1970-01-01
    • 2014-10-03
    • 2020-04-26
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    相关资源
    最近更新 更多