Alex Rivera | Logout

Screen Scraping HTML with C#

Asked 2011-01-03T19:46:04.987
12

I have been given the task at work of screen scraping one of our legacy web apps to extract certain data from the code. The data is formatted and "should" be displayed exactly the same every time. I am just not sure how to go about doing this. It's a full html file with header and footer navigations but in the middle of all this is the data I need.

I need to extract the Company Name value, Contact Name, Telephone, email address, etc.

Here is an example of what the code looks like:

...html above here

<br /><br />
<table cellpadding="0" cellspacing="12" border="0">
    <tr>
        <td valign="top" align="center">
            <!-- Company Info -->

            <table cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td class="black">
                        <table cellspacing="1" cellpadding="0" border="0" width="370">
                            <tr>
                                <th>ABC INDUSTRIES</th>
                            </tr>
                            <tr>
                                <td class="search">

                                    <table cellpadding="5" cellspacing="0" border="0" width="100%">
                                        <tr>
                                            <td>
                                                <table cellpadding="1" cellspacing="0" border="0" width="100%">
                                                   <tr>
                                                        <td align="center" colspan="2"><hr></td>
                                                    </tr>
                                                    <tr>
                                                        <td align="right" nowrap><b><font color="FF0000">Contact Person&nbsp;<img src=
Edit
Report

1 Answer

1

If the page comments and table layout code are the same whenever called, I would pull the page into a string and use a series of .IndexOf and .Substring functions to parse out the data. Use the IndexOf function to find the starting and ending indexes of each field. Use these field indexes in the Substring function to grab the data.

It's not pretty but gets the job done.

answered 2011-01-03T20:01:48.043

Your Answer