Extract records from HTML of another site

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SteveJ

    #1

    Extract records from HTML of another site

    All,
    Can someone help me solve the next step.

    First of all let me say I'm new to php. I pieced the following code together
    from samples
    I found on the net and a book I bought called PHP Cookbook. So please
    forgive me if this isn't the best approach - I'm open to suggestions
    I finally got my code to work that logs into another site and pulls the
    orderstatus page to my server.

    <?php
    /*
    Login to site
    */
    $ch = curl_init();
    curl_setopt($ch , CURLOPT_COOKIEJ AR, "/tmp/cookieFileName" );
    curl_setopt($ch ,
    CURLOPT_URL,"ht tps://www.homier.com/default.asp?pag e=signin");
    curl_setopt($ch , CURLOPT_POST, 1);
    curl_setopt($ch , CURLOPT_POSTFIE LDS,
    "EMail=homieror ders@swbell.net &Password=1040e z");
    ob_start(); // prevent any output
    curl_exec ($ch); // execute the curl command
    ob_end_clean(); // stop preventing output
    curl_close ($ch);
    unset($ch);

    /*
    Dump html of orderstatus page into a file on my server
    */
    $fh = fopen('raw_orde rstatus.html',' w') or die($php_errorm sg);
    $ch = curl_init();
    curl_setopt($ch , CURLOPT_RETURNT RANSFER,1);
    curl_setopt($ch , CURLOPT_COOKIEF ILE, "/tmp/cookieFileName" );
    curl_setopt($ch ,
    CURLOPT_URL,"ht tps://www.homier.com/default.asp?pag e=orderstatus") ;
    curl_setopt($ch , CURLOPT_FILE, $fh);
    curl_exec ($ch);
    curl_close ($ch);
    ?>

    My problem: How can I capture only the data in the "<td
    class='n8n_CCCC CC_default>" tags?
    Is there a way to do this at file creation?
    I checked with my ISP and I can't use LYNX -DUMP file.html

    The goal here is to load these records into MYSQL database.

    Thanks in advance
    Steve


    The html code looks like this


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>homier.c om</title>
    <LINK REL='stylesheet ' TYPE='text/css' HREF='hdcstyle. css'>
    <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
    <meta name='descripti on' content=' '>
    <meta name='keywords' content=' '>
    <meta name='revisit-after' content='7 days'>
    <meta name='robots' content='all, index, follow'>
    <meta http-equiv="Pragma" content="no-cache">
    <script language="JavaS cript"
    src="https://www.thawte.com/html/certdetails.js"
    type="text/javascript"></script>

    </head>
    <body leftmargin='0' topmargin='0' rightmargin='0' bottommargin='0 '
    marginwidth='0' marginheight='0 '>
    <table cellspacing="0" cellpadding="0" border="0" width='770'>
    <tr>
    <td align='left' valign='top'>
    <img src='https://www.homier.com/graphics/hdclogo3.jpg' border='0'
    width='370' height='58' alt='Homier Distributing Company, Inc.'></td>

    <td align='right' valign='top'>
    <table cellspacing="0" cellpadding="0" border="0">
    <tr><td align='right' valign='middle' class='menu'>
    <a href='https://www.homier.com/default.asp?pag e=cart' class='menu'><i mg
    src='https://www.homier.com/graphics/cart.gif' border='0' width='17'
    height='21' align='absmiddl e'>Shopping Cart</a>
    | <a href='https://www.homier.com/default.asp?pag e=stores' class='menu'>Sa le
    Locations</a>
    | <a href='https://www.homier.com/default.asp?pag e=about' class='menu'>Ab out
    Us</a>
    | <a href='https://www.homier.com/default.asp?pag e=contacts'
    class='menu'>Co ntact Us</a>
    | <a href='https://www.homier.com/default.asp?pag e=faq' class='menu'>FA Q</a>
    </td></tr>
    <tr><td align='right' valign='middle' class='menu'>
    <a href='https://www.homier.com/default.asp?pag e=myprofile' class='menu'>My
    Account</a>
    | <a href='https://www.homier.com/default.asp?pag e=orderstatus'
    class='menu'>Or der Status</a> |
    <a href='https://www.homier.com/default.asp?pag e=dealers'
    class='menu'>De aler Extranet</a>
    </td></tr>

    </table>
    </td>
    </tr>
    </table>
    <table cellspacing="0" cellpadding="0" border="0" width='770'>
    <tr>
    <td colspan='2' valign='top' align='center'
    background='htt ps://www.homier.com/graphics/hdcbk3.jpg'>
    <table cellspacing='0' cellpadding='0' border='0'>
    <tr><table cellspacing='0' cellpadding='0' border='0'><tr>
    <td align='middle' valign='top'><i mg
    src='https://www.homier.com/graphics/tab_start.gif' border='0' width='5'
    height='21'></td>
    <td align='middle' valign='middle' class='tabs' style='backgrou nd-image:
    url(https://www.homier.com/graphics/tab_bg.gif);'>< a
    href='https://www.homier.com/default.asp?dpt =0' class='link'
    onmouseover="th is.style.color= 'yellow'"
    onmouseout="thi s.style.color=' white'">Home</a></td>
    <td align='middle' valign='top'><i mg
    src='https://www.homier.com/graphics/tab_ctr.gif' border='0' width='9'
    height='21'></td>
    <td align='middle' valign='middle' class='tabs' style='backgrou nd-image:
    url(https://www.homier.com/graphics/tab_bg.gif);'>< a
    href='https://www.homier.com/default.asp?dpt =1' class='link'
    onmouseover="th is.style.color= 'yellow'"
    onmouseout="thi s.style.color=' white'">Tools</a></td>
    <td align='middle' valign='top'><i mg
    src='https://www.homier.com/graphics/tab_ctr.gif' border='0' width='9'
    height='21'></td>
    <td align='middle' valign='middle' class='tabs' style='backgrou nd-image:
    url(https://www.homier.com/graphics/tab_bg.gif);'>< a
    href='https://www.homier.com/default.asp?dpt =2' class='link'
    onmouseover="th is.style.color= 'yellow'"
    onmouseout="thi s.style.color=' white'">Automot ive</a></td>
    <td align='middle' valign='top'><i mg
    src='https://www.homier.com/graphics/tab_ctr.gif' border='0' width='9'
    height='21'></td>
    <td align='middle' valign='middle' class='tabs' style='backgrou nd-image:
    url(https://www.homier.com/graphics/tab_bg.gif);'>< a
    href='https://www.homier.com/default.asp?dpt =4' class='link'
    onmouseover="th is.style.color= 'yellow'"
    onmouseout="thi s.style.color=' white'">Electro nics</a></td>
    <td align='middle' valign='top'><i mg
    src='https://www.homier.com/graphics/tab_ctr.gif' border='0' width='9'
    height='21'></td>
    <td align='middle' valign='middle' class='tabs' style='backgrou nd-image:
    url(https://www.homier.com/graphics/tab_bg.gif);'>< a
    href='https://www.homier.com/default.asp?dpt =6' class='link'
    onmouseover="th is.style.color= 'yellow'"
    onmouseout="thi s.style.color=' white'">Collect ibles</a></td>
    <td align='middle' valign='top'><i mg
    src='https://www.homier.com/graphics/tab_end.gif' border='0' width='5'
    height='21'></td>
    </tr>
    </table>
    <table cellspacing='0' cellpadding='0' border='0'><tr>
    <td align='middle' valign='top'><i mg
    src='https://www.homier.com/graphics/tab_start.gif' border='0' width='5'
    height='21'></td>
    <td align='middle' valign='middle' class='tabs' style='backgrou nd-image:
    url(https://www.homier.com/graphics/tab_bg.gif);'>< a
    href='https://www.homier.com/default.asp?dpt =3' class='link'
    onmouseover="th is.style.color= 'yellow'"
    onmouseout="thi s.style.color=' white'">Outdoor Living</a></td>
    <td align='middle' valign='top' class='tab_ends '><img
    src='https://www.homier.com/graphics/tab_ctr.gif' border='0' width='9'
    height='21'></td>
    <td align='middle' valign='middle' class='tabs' style='backgrou nd-image:
    url(https://www.homier.com/graphics/tab_bg.gif);'>< a
    href='https://www.homier.com/default.asp?dpt =5' class='link'
    onmouseover="th is.style.color= 'yellow'"
    onmouseout="thi s.style.color=' white'">Home Furnishings</a></td>
    <td align='middle' valign='top' class='tab_ends '><img
    src='https://www.homier.com/graphics/tab_ctr.gif' border='0' width='9'
    height='21'></td>
    <td align='middle' valign='middle' class='tabs' style='backgrou nd-image:
    url(https://www.homier.com/graphics/tab_bg.gif);'>< a
    href='https://www.homier.com/default.asp?dpt =7' class='link'
    onmouseover="th is.style.color= 'yellow'"
    onmouseout="thi s.style.color=' white'">General Merchandise</a></td>
    <td align='middle' valign='top' class='tab_ends '><img
    src='https://www.homier.com/graphics/tab_ctr.gif' border='0' width='9'
    height='21'></td>
    <td align='middle' valign='middle' class='tabs' style='backgrou nd-image:
    url(https://www.homier.com/graphics/tab_bg.gif);'>< a
    href='https://www.homier.com/default.asp?dpt =99' class='link'
    onmouseover="th is.style.color= 'yellow'"
    onmouseout="thi s.style.color=' white'">See All</a></td>
    <td align='middle' valign='top'><i mg
    src='https://www.homier.com/graphics/tab_end.gif' border='0' width='5'
    height='21'></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    <table cellspacing='0' cellpadding='0' border='0' width='770'>
    <form action='https://www.homier.com/default.asp' method='post'>
    <tr>
    <td class='tab_back ground' height='28' valign='middle' align='left'
    width='500' nowrap>
    <input type='hidden' name='page' value='search'>
    <input type='hidden' name='pgndx' value='1'>
    &nbsp;&nbsp;Sea rch in:
    <select name='SearchIn' class='search'>
    <option value='0'
    SELECTED[color=blue]
    >All Departments</option>[/color]
    <option value='99'[color=blue]
    >Catalog Number</option>[/color]
    <option value='1'[color=blue]
    >Tools</option>[/color]
    <option value='2'[color=blue]
    >Automotive</option>[/color]
    <option value='3'[color=blue]
    >Outdoor Living</option>[/color]
    <option value='4'[color=blue]
    >Electronics</option>[/color]
    <option value='5'[color=blue]
    >Home Furnishings</option>[/color]
    <option value='6'[color=blue]
    >Collectibles </option>[/color]
    <option value='7'[color=blue]
    >General Merchandise</option>[/color]
    </select>
    &nbsp;for:
    <input type='text' name='SearchFor ' size='15' maxlength='30' class='search'
    value=''>
    <input type='image' src='https://www.homier.com/graphics/go.gif' border='0'
    align='absmiddl e' alt='Click to search'>
    </td>
    <td align='left' class='b8n_whit e_000f46' width='100%'
    nowrap>800-348-5004</td>
    <td align='right' class='b8n_whit e_000f46' width='100' nowrap>
    <a href='https://www.homier.com/default.asp?pag e=logout'
    class='service' ><img src='https://www.homier.com/graphics/lock.gif'
    width='11' height='15' border='0' align='absmiddl e'>&nbsp;Sign Out&nbsp;
    </a></td>
    </tr>
    </form>
    </table>
    <table cellspacing='0' cellpadding='0' border='0' width='770'>
    <tr><td valign='top' align='center'>
    <table cellpadding='0' cellspacing='0' border='0' width='750'>
    <tr><td class='e16n_000 f46_default'>Or der Status & Tracking</td></tr>
    <tr><td align='center'> <img src='https://www.homier.com/graphics/grey.gif'
    border='0' width='750' height='1'></td></tr>
    <tr><td class='b9in_def ault_default' align='right'>O rders 8/1/2004 -
    10/30/2004</td></tr>
    <tr><td>&nbsp ;</td></tr>
    </table>
    <table cellpadding='2' cellspacing='0' border='0' width='750'>
    <tr>
    <td class='b8n_defa ult_default'>Or der #</td>
    <td class='b8n_defa ult_default'>Re f</td>
    <td class='b8n_defa ult_default'>Or der Date</td>
    <td class='b8n_defa ult_default'>Sh ipped To</td>
    <td class='b8n_defa ult_default'>St atus</td>
    <td class='b8n_defa ult_default'>Tr acking</td>
    </tr>
    <tr>
    <td class='n8n_CCCC CC_default'><a
    href='https://www.homier.com/default.asp?pag e=orderdetail&o rderid=307377'> 16
    0710SE</a></td>
    <td class='n8n_CCCC CC_default'>307 377</td>
    <td class='n8n_CCCC CC_default'>10/29/2004</td>
    <td class='n8n_CCCC CC_default'>Sta n Johnson Blue Springs, MO</td>
    <td class='n8n_CCCC CC_default'>AR Processing</td>
    <td class='n8n_CCCC CC_default'><a
    href='https://www.homier.com/default.asp?pag e=tracking&trac kingnumber='></a>
    </td>
    </tr>
    </table>

    </td>
    </tr>
    <tr><td colspan='2' align='center'> <table cellpadding='0' cellspacing='0'
    border='0'>
    <tr><td align='center'> &nbsp;</td></tr>
    <tr><td align='center'> <img src='https://www.homier.com/graphics/grey.gif'
    border='0' width='350' height='1'></td></tr>
    <tr><td align='center'> &nbsp;</td></tr>
    <tr><td align='center' class='n7n_defa ult_default'>
    <a href='https://www.homier.com/default.asp?pag e=privacy'
    class='menu'>Pr ivacy & Security</a>
    | <a href='https://www.homier.com/default.asp?pag e=terms' class='menu'>Te rms
    of Use</a>
    | <a href='https://www.homier.com/default.asp?pag e=pressreleases '
    class='menu'>Pr ess Releases</a>
    </td></tr>
    <tr><td align='center' class='n7n_defa ult_default'>
    <a href='https://www.homier.com/default.asp?pag e=sitemap' class='menu'>Si te
    Map</a>
    | <a href='https://www.homier.com/default.asp?pag e=warranty'
    class='menu'>Wa rranty & Returns</a>
    | <a href='https://www.homier.com/default.asp?pag e=shipping'
    class='menu'>Sh ipping Policy</a>
    </td></tr>
    <tr><td>&nbsp ;</td></tr>
    <tr><td align='center' class='copyrigh t'><a
    href='https://www.homier.com/default.asp?pag e=copyright'>Co pyright</a>&nbsp;
    &copy;2004, Homier Distributing Company. All rights reserved.</td></tr>
    </table>
    </td></tr>
    </table>

    </body>
    </html>


Working...