I have one static HTML page table with some information in it, I am trying to extract the contents of the Table
HTML Table:-
HTML / XML
<table border="0" cellpadding="5" cellspacing="0" width="165">
<tr>
<td nowrap>
<div class="saadirname">
Pradeep
G
</div>
<span class="saadirtext">
State College
<br>
First Grade
<br>
Library
<br>
</span><br>
<span class="saadirheader">Mailing Address:</span><br>
<span class="saadirtext">
<!--If using company address-->
Welcome Society
<br>
Library Arch
<br>
# 20 State Street
<br>
Mail Road
,
WI
<img src="/images/spacer.gif" alt="" height="1" width="5" border="0">
5000-1000
<img src="/images/spacer.gif" alt="" height="1" width="5" border="0">
IND
</span>
<p>
<b class="saadirheader">Phone:</b> <span class="saadirtext">(916) 060-6480</span><br>
<b class="saadirheader">Fax:</b> <span class="saadirtext">(916) 264-6336</span><br>
<b class="saadirheader">Email:</b>
<a href="MailTo:[email protected] "><span class="saadirtext">
[email protected]</span></a><br>
<br>
<b class="saadirheader">Membership Type:</b>
<span class="saadirtext">Individual</span><br>
<br>
</p></td>
</tr>
</table>
Program :-
static void Main()
{
StreamReader str = new StreamReader("C:\\member.html");
string SFile = str.ReadToEnd();
Regex regex = new Regex(
@"<tr>
(
\s*
<td[^>]*>
\s*<div[^>]*>\s*
(\s*<!--((?!-->).)*-->)*\s*
(?<value>.*?)
(\s*<!--((?!-->).)*-->)*\s*
</div>\s*
</td>
)+
\s*</tr>
",
RegexOptions.Singleline | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
foreach (Match m in regex.Matches(SFile))
{
foreach (Capture item in m.Groups["value"].Captures)
{
Console.WriteLine(item.Value);
}
Console.WriteLine();
}
Console.ReadLine();
}I am getting the below output ....Entire table is getting printed with tags. can we handle the span,br tags ??
There is one more table in the Page Footer part, can we start the process after this line
HTML / XML
<!--START FOOTER FILE-->OutPut :-
HTML / XML |
Answers
Know the answer? Post it. Somebody with the same question will find it here.