1

I have posted my HTML below. In which I want to get the name value from within my textbox area. I've tried several processes and I'm still not getting any valid solution. Please check my HTML and code snippet, and show me a possible solution.

The name prefix will always stay the same when I refresh the page. However, the last name within the "name" area will change, but will always contain the literal "mr." as the first 3 digits. regex as ([mM]r.\ ) - Four digits if you consider the literal space. Below is my table example.

<table>
<tr><td><b>Your Name is </b> mr. kamrul</td></tr>
<tr><td><b>your age </b> 12</td></tr>
<tr><td><b>Email:</b>kennethdasma30@gmail.com</td></tr>
<tr><td><b>job title</b> sales man</td></tr>
</table>

As shown below I am trying this process using listbox but I am not receiving anything.

 HtmlElementCollection bColl = 
 webBrowser1.Document.GetElementsByTagName("table");
        foreach (HtmlElement bEl in bColl)
        {
            if (bEl.GetAttribute("table") != null)
            {
                listBox1.Items.Add(bEl.GetAttribute("table"));
            }
        }

If anyone ca give me an idea of how I am able to receive all in the browser window as ("mr. " + text) within my list box I would appreciate it. Also, if you can explain the answer verbosely and with good comments I would appreciate it, as I'd like to understand the answer in greater detail as well.

Mike Horstmann
  • 580
  • 2
  • 9
  • Please read the instructions on [how to ask a good question](http://stackoverflow.com/help/how-to-ask). Right now, we can only guess you are using C#. Also, it is not clear what string you want to obtain. – Wiktor Stribiżew Sep 07 '15 at 17:30

1 Answers1

0

Here is one simple way using Regex, assuming that the format of your html page doesn't change.

Regex re = new Regex(@"(?<=<tr><td><b>Your\sName\sis\s?</b>\s?)[mM]r\.\s.+?(?=</td></tr>)", RegexOptions.Singleline);
foreach (Match match in re.Matches(webBrowser1.DocumentText))
{
    listBox1.Items.Add(match.Value);
}
Pradeep Kumar
  • 6,836
  • 4
  • 21
  • 47
  • can you solving my this link issue same just in there number need pls check http://stackoverflow.com/questions/32423115/how-received-number-in-my-textbox1-using-windows-form – basilia lufkin Sep 08 '15 at 11:59