This project has moved and is read-only. For the latest updates, please go here.

Parsing by Class Name?

Nov 13, 2008 at 12:16 AM
I'm trying to parse some info from this url:

Here is the HTML I'm trying to parse which are a bunch of tables, in it I'm trying to get by class name to get the Company Name, Address, & Phone. Which are defined by class="listing_name", class="sml_txt", and phone_txt"  I've tried everything I can think of and I"m getting no where fast.  Below is a javascript that gets exactly what I need but I want to be able to dump into database.  If I could somehow do exactly what is i the javascript it would work.  Any help would be appreciated.

       <td style="padding-left: 10px;" align="left" valign="top"><div><a class="listing_name" href="url">Kids R Kids</a></div><div class="sml_txt">6262 Upper Lake Dr<br>Kingwood, TX 77346</div><div class="phone_txt" style="padding-bottom: 5px;">(281) 973-5838</div><div class="sml_txt" style="padding-bottom: 5px;"><i>Come And See The Difference</i></div><div style="padding-bottom: 5px;"><a href="url" target="_blank"><img src="url" alt="" border="0"></a></div><div class="sml_txt" style="padding-bottom: 5px;"><a href="url" target="_blank" class="b_link_txt">Visit Website</a></div></td></tr>
       <td colspan="2" style="padding-left: 10px; text-align: left;"><a class="b_link_txt" href="url">More Info</a>  |  <a class="b_link_txt" href="url">Map</a>  |  <a class="b_link_txt" href="url">Directions</a>

       <td colspan="2">&nbsp;</td>

Javascript to parse requested data
var test = document.getElementsByClassName("listing_name");
var theData = new Array();
for (var i = 0; i < test.length; i++) {
theData[i] = new Array();
theData[i][0] = test[i].textContent;
theData[i][1] = test[i].parentNode.nextSibling.innerHTML;
theData[i][2] = test[i].parentNode.nextSibling.nextSibling.innerHTML;