【问题标题】:C# Windows application- How to span tag value show in textbox1?C# Windows 应用程序 - 如何在 textbox1 中显示标签值?
【发布时间】:2016-04-10 01:52:16
【问题描述】:

其实我想跨越我的textbox1.Text区域中显示的数据值。

这是完整的代码。

<td id="yiv9101838563i4" style="padding:0;padding-top:25px;font-family:'Segoe UI', Tahoma, Verdana, Arial, sans-serif;font-size:14px;color:#2a2a2a;">Security code: <span style="font-family:'Segoe UI Bold', 'Segoe UI Semibold', 'Segoe UI', 'Helvetica Neue Medium', Arial, sans-serif;font-size:14px;font-weight:bold;color:#2a2a2a;">7201</span></td>

这是收到的代码

<span style="font-family:'Segoe UI Bold', 'Segoe UI Semibold', 'Segoe UI', 'Helvetica Neue Medium', Arial, sans-serif;font-size:14px;font-weight:bold;color:#2a2a2a;">7201</span>

我已经检查了许多来源以寻找解决方案,但我未能找到解决方案,因此我正在等待任何好的答复。

我想知道如何跨越textbox1.Text 区域中显示的值。

我也尝试了下面的代码,但这不起作用。

HtmlElementCollection bColl = webBrowser3.Document.GetElementsByTagName("span");
foreach (HtmlElement bEl in bColl)
{
    if (bEl.GetAttribute("style").Contains("font-family:'Segoe UI Bold'"))
        txtlink.Text = bEl.OuterHtml;
}

【问题讨论】:

  • 期望的输出是什么?
  • 7201 这个数字我想在我的文本框中显示,但不显示任何输出。 Mabe我在某个地方弄错了。请帮助我。
  • 所以,为了确认,您希望 RegEx 从您问题的第一个 HTML 字符串中选择 7201?

标签: c# regex getattribute htmlelements


【解决方案1】:

试试这个正则表达式:

<td\s.*?>.*?<span\s.*?>(.*?)<\/span><\/td>

你想要的数据存储在1stCapture Group

Live Demo on Regex101

它是如何工作的:

<td\s.*?>          # Opening <td> with attributes
.*?                # Optional Data - i.e. Security Code: (Lazy)
<span\s.*?>        # Opening <span> with attributes
(.*?)              # The data you need to Capture - i.e. 7201
<\/span>           # Closing </span>
<\/td>             # Closing </td>

【讨论】:

  • 亲爱的朋友们,我完全不知道如何使用正则表达式,所以你能给我完整的代码然后我去测试。请为我做我正在等待您的更新。谢谢
  • @browsersumon StackOverflow 不是免费的编码服务。首先,尝试Googling。然后找一些在C#中使用RegEx的教程
  • @browsersumon 试试this site 和this site。这就是我要给你的所有信息。
猜你喜欢
  • 1970-01-01
  • 2023-03-26
  • 2011-05-15
  • 2012-09-06
  • 2018-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多