Link to home
Start Free TrialLog in
Avatar of fakir420
fakir420

asked on

Parse HTML Table

I need example code to parse the following HTML table into a list or array - I'm not sure the best way as I'm new to Python coming from VB.  So far I've been able to get the HTML and split out just the table portion, but I now need to parse the table into (preferrably) a comma delimited list of the tables rows/columns.  I would really like to see and example including parsing out all the unwanted text and just the column headings/column data text.  Also any comments in the code to show me what is going on would help out alot.

Here is the output I'd like to get - this is the first two rows of the table:

Date|Time|From|Duration (hh:mm:ss)
Jun 02, 2006|02:53 PM|13012684637|00:01:00


<---------------Start Table--------------->      
        <table width="100%" id="received_calls" border="0" cellpadding="1" cellspacing="2">
                        <tr class="tableheader2">
                              <td align=left colspan=5 class="tableheader2">Received Calls</td>
                </tr>
               
                           
                            <tr>
                                <TD nowrap class="tableheader9" width="20%" >Date</TD>
                                <TD nowrap class="tableheader9" width="20%" >Time</TD>
                             
                                       <TD nowrap class="tableheader9" width="35%" >
                                               <div class="iconButton"></div><div class="iconButton"></div>From</TD>
                               
                                <TD nowrap class="tableheader9" width="25%" >Duration (hh:mm:ss)</TD>
                            </tr>
                           
                            <tr class="tablebody1">
                               
                               
                               
                                <TD nowrap >Jun 02, 2006&nbsp;</TD>
                                <TD nowrap >03:56 PM&nbsp;</TD>
                           
                                    <TD nowrap ><!-- forward call setion -->
                                         

                                         <!--  from caller setion -->

                                           
                                      <div class="iconButton"><a href="javascript:void(0)" onclick="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', STICKY, CSSCLASS);" onmouseover="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', CSSCLASS);" onmouseout="return nd();"><img src="/static/common-web/images/activity_icons/icon_caller_id.gif" border="0" ></a></div>

                                         <div class="iconButton"><img src="/static/common-web/images/activity_icons/icon_filler.gif" border="0" ></div>
                                             
                                          <div class="phoneNumber">13012684637</div>
                                    </TD>
                               
                                    <TD nowrap > 
                                                 00:02:00</TD>
                            </tr>
                           
                            <tr >
                               
                               
                               
                                <TD nowrap >Jun 02, 2006&nbsp;</TD>
                                <TD nowrap >02:53 PM&nbsp;</TD>
                           
                                    <TD nowrap ><!-- forward call setion -->
                                         

                                         <!--  from caller setion -->

                                           
                                      <div class="iconButton"><a href="javascript:void(0)" onclick="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', STICKY, CSSCLASS);" onmouseover="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', CSSCLASS);" onmouseout="return nd();"><img src="/static/common-web/images/activity_icons/icon_caller_id.gif" border="0" ></a></div>

                                         <div class="iconButton"><img src="/static/common-web/images/activity_icons/icon_filler.gif" border="0" ></div>
                                             
                                          <div class="phoneNumber">13012684637</div>
                                    </TD>
                               
                                    <TD nowrap > 
                                                 00:01:00</TD>
                            </tr>
                           
                            <tr class="tablebody1">
                               
                               
                               
                                <TD nowrap >Jun 02, 2006&nbsp;</TD>
                                <TD nowrap >12:29 PM&nbsp;</TD>
                           
                                    <TD nowrap ><!-- forward call setion -->
                                         

                                         <!--  from caller setion -->

                                           
                                      <div class="iconButton"><a href="javascript:void(0)" onclick="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', STICKY, CSSCLASS);" onmouseover="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', CSSCLASS);" onmouseout="return nd();"><img src="/static/common-web/images/activity_icons/icon_caller_id.gif" border="0" ></a></div>

                                         <div class="iconButton"><img src="/static/common-web/images/activity_icons/icon_filler.gif" border="0" ></div>
                                             
                                          <div class="phoneNumber">13012684637</div>
                                    </TD>
                               
                                    <TD nowrap > 
                                                 00:01:00</TD>
                            </tr>
                           
                            <tr >
                               
                               
                               
                                <TD nowrap >Jun 02, 2006&nbsp;</TD>
                                <TD nowrap >11:55 AM&nbsp;</TD>
                           
                                    <TD nowrap ><!-- forward call setion -->
                                         

                                         <!--  from caller setion -->

                                           
                                      <div class="iconButton"><a href="javascript:void(0)" onclick="return overlib('<CENTER>15408774179<br><br><b>PCS PHONE    VA</b>', STICKY, CSSCLASS);" onmouseover="return overlib('<CENTER>15408774179<br><br><b>PCS PHONE    VA</b>', CSSCLASS);" onmouseout="return nd();"><img src="/static/common-web/images/activity_icons/icon_caller_id.gif" border="0" ></a></div>

                                         <div class="iconButton"><img src="/static/common-web/images/activity_icons/icon_filler.gif" border="0" ></div>
                                             
                                          <div class="phoneNumber">15408774179</div>
                                    </TD>
                               
                                    <TD nowrap > 
                                                 00:06:00</TD>
                            </tr>
                           
                            <tr class="tablebody1">
                               
                               
                               
                                <TD nowrap >Jun 02, 2006&nbsp;</TD>
                                <TD nowrap >11:41 AM&nbsp;</TD>
                           
                                    <TD nowrap ><!-- forward call setion -->
                                         

                                         <!--  from caller setion -->

                                           
                                      <div class="iconButton"><a href="javascript:void(0)" onclick="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', STICKY, CSSCLASS);" onmouseover="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', CSSCLASS);" onmouseout="return nd();"><img src="/static/common-web/images/activity_icons/icon_caller_id.gif" border="0" ></a></div>

                                         <div class="iconButton"><img src="/static/common-web/images/activity_icons/icon_filler.gif" border="0" ></div>
                                             
                                          <div class="phoneNumber">13012684637</div>
                                    </TD>
                               
                                    <TD nowrap > 
                                                 00:01:00</TD>
                            </tr>
                           
                            <tr >
                               
                               
                               
                                <TD nowrap >Jun 02, 2006&nbsp;</TD>
                                <TD nowrap >11:41 AM&nbsp;</TD>
                           
                                    <TD nowrap ><!-- forward call setion -->
                                         

                                         <!--  from caller setion -->

                                           
                                      <div class="iconButton"><a href="javascript:void(0)" onclick="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', STICKY, CSSCLASS);" onmouseover="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', CSSCLASS);" onmouseout="return nd();"><img src="/static/common-web/images/activity_icons/icon_caller_id.gif" border="0" ></a></div>

                                         <div class="iconButton"><img src="/static/common-web/images/activity_icons/icon_filler.gif" border="0" ></div>
                                             
                                          <div class="phoneNumber">13012684637</div>
                                    </TD>
                               
                                    <TD nowrap > 
                                                 00:01:00</TD>
                            </tr>
                           
                            <tr class="tablebody1">
                               
                               
                               
                                <TD nowrap >Jun 02, 2006&nbsp;</TD>
                                <TD nowrap >11:40 AM&nbsp;</TD>
                           
                                    <TD nowrap ><!-- forward call setion -->
                                         

                                         <!--  from caller setion -->

                                           
                                      <div class="iconButton"><a href="javascript:void(0)" onclick="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', STICKY, CSSCLASS);" onmouseover="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', CSSCLASS);" onmouseout="return nd();"><img src="/static/common-web/images/activity_icons/icon_caller_id.gif" border="0" ></a></div>

                                         <div class="iconButton"><img src="/static/common-web/images/activity_icons/icon_filler.gif" border="0" ></div>
                                             
                                          <div class="phoneNumber">13012684637</div>
                                    </TD>
                               
                                    <TD nowrap > 
                                                 00:01:00</TD>
                            </tr>
                           
                            <tr >
                               
                               
                               
                                <TD nowrap >Jun 01, 2006&nbsp;</TD>
                                <TD nowrap >05:49 PM&nbsp;</TD>
                           
                                    <TD nowrap ><!-- forward call setion -->
                                         

                                         <!--  from caller setion -->

                                           
                                      <div class="iconButton"><a href="javascript:void(0)" onclick="return overlib('<CENTER>18666894118<br><br><b>800 SERVICE</b>', STICKY, CSSCLASS);" onmouseover="return overlib('<CENTER>18666894118<br><br><b>800 SERVICE</b>', CSSCLASS);" onmouseout="return nd();"><img src="/static/common-web/images/activity_icons/icon_caller_id.gif" border="0" ></a></div>

                                         <div class="iconButton"><img src="/static/common-web/images/activity_icons/icon_filler.gif" border="0" ></div>
                                             
                                          <div class="phoneNumber">18666894118</div>
                                    </TD>
                               
                                    <TD nowrap > 
                                                 00:01:00</TD>
                            </tr>
                           
                            <tr class="tablebody1">
                               
                               
                               
                                <TD nowrap >Jun 01, 2006&nbsp;</TD>
                                <TD nowrap >04:48 PM&nbsp;</TD>
                           
                                    <TD nowrap ><!-- forward call setion -->
                                         

                                         <!--  from caller setion -->

                                           
                                      <div class="iconButton"><a href="javascript:void(0)" onclick="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', STICKY, CSSCLASS);" onmouseover="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', CSSCLASS);" onmouseout="return nd();"><img src="/static/common-web/images/activity_icons/icon_caller_id.gif" border="0" ></a></div>

                                         <div class="iconButton"><img src="/static/common-web/images/activity_icons/icon_filler.gif" border="0" ></div>
                                             
                                          <div class="phoneNumber">13012684637</div>
                                    </TD>
                               
                                    <TD nowrap > 
                                                 00:01:00</TD>
                            </tr>
                           
                            <tr >
                               
                               
                               
                                <TD nowrap >Jun 01, 2006&nbsp;</TD>
                                <TD nowrap >04:48 PM&nbsp;</TD>
                           
                                    <TD nowrap ><!-- forward call setion -->
                                         

                                         <!--  from caller setion -->

                                           
                                      <div class="iconButton"><a href="javascript:void(0)" onclick="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', STICKY, CSSCLASS);" onmouseover="return overlib('<CENTER>13012684637<br><br><b>CELL PHONE   MD</b>', CSSCLASS);" onmouseout="return nd();"><img src="/static/common-web/images/activity_icons/icon_caller_id.gif" border="0" ></a></div>

                                         <div class="iconButton"><img src="/static/common-web/images/activity_icons/icon_filler.gif" border="0" ></div>
                                             
                                          <div class="phoneNumber">13012684637</div>
                                    </TD>
                               
                                    <TD nowrap > 
                                                 00:01:00</TD>
                            </tr>
                           
                           

                           
                       
                  </table>
<---------------End Table--------------->
Avatar of fakir420
fakir420

ASKER

Actually I guess I need a pipe delimited list - as shown in my example.  I changed this once I realized the "Date" had a comma in it but forgot to change this in the original post.
ASKER CERTIFIED SOLUTION
Avatar of RichieHindle
RichieHindle

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, this works perfectly!