+ Reply to Thread
Results 1 to 2 of 2

Thread: Screen Scrape Help

  1. #1
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    Screen Scrape Help

    I am new to working with this type of code any assistance is greatly appreciated. Below is the code that I am trying to get working. I am stuck on the portion where I add the data to the database.

    Code:
    //Connect to page and retreive content
    $url = "http://www.site.com";
    $raw = file_get_contents($url);
    
    // remove all lines from the code
    $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
    $content = str_replace($newlines, "", html_entity_decode($raw));
    
    // Select the table that will be used
    $start = strpos($content,'<TABLE NAME="results" border="0" cellpadding="2" cellspacing="0" width="660">');
    $end = strpos($content,'</TABLE>',$start) + 8;
    $table = substr($content,$start,$end-$start);
    
    
    preg_match_all("|<tr(.*)</tr>|U",$table,$rows);
    
    foreach ($rows[0] as $row){
    
        if ((strpos($row,'<TH')===false)){
      
            preg_match_all("|<TD(.*)</TD>|U",$row,$cells);
          
            $list1 = strip_tags($cells[0][0]);
            $list2 = strip_tags($cells[0][1]);
            $list3 = strip_tags($cells[0][2]);
              
        }
    
    }
    mysql_query("INSERT INTO station (name, address, city, state, zip, phone, notes) VALUES ('$name', '$address', '$city', '$state', '$zip', 'phone', 'notes')") or die(mysql_error());
    This is a sample of what the coding looks like after $content
    Code:
    <TABLE NAME="results" border="0" cellpadding="2" cellspacing="0" width="660"><TR><TD valign="top" class="tdmedium" colspan="3"><P><CENTER><B class="bigblue">All E85 Pumps in Wisconsin</B></CENTER></P></TD></TR><tr><TD class="tdbasic" valign="top"><B>Pump 24</B><BR>451 Main St.<BR>Adams, WI 53910<BR>608-339-3626<BR><BR><BR></TD><TD class="tdbasic" valign="top"><B>Holiday Station</B><BR>Highway 8<BR>Almena, WI 54805<BR>715-357-3957<BR><BR><BR></TD><TD class="tdbasic" valign="top"><B>Kwik Trip #451</B><BR>455 State Hwy 64<BR>Antigo, WI 54409<BR>715-623-6655<BR><BR><BR></TD></tr><tr><TD class="tdbasic" valign="top"><B>Kwik Trip #452</B><BR>3721 W. College Ave.<BR>Appleton, WI 54914<BR>920-993-9089<BR><BR><BR></TD><TD class="tdbasic" valign="top"><B>Express Convenience Center</B><BR>2175 South Memorial Drive<BR>Appleton, WI 54915<BR>920-380-0492<BR><BR><BR></TD><TD class="tdbasic" valign="top"><B>Sanborn Station</B><BR>411 Sanborn Ave<BR>Ashland, WI 54806<BR>715-682-2745<BR><BR><BR></TD></tr></TABLE>

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Screen Scrape Help

    I'm not seeing any real problem with the insert, unless one of the pieces of data you are trying to insert is bad, ie unescaped characters. Where are $name, $address...$notes defined? Also, I'm guessing $notes and $phone are variables and not the words 'notes' and 'phone'.

    When I can't get a query to work, I usually try doing it manually in phpmyadmin. It gives more helpful error messages. When that works, then I go back and work it into the code.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

+ Reply to Thread

Similar Threads

  1. How to stretch a site on any screen, anyone?
    By 1 angel undercover in forum Programming Help
    Replies: 11
    Last Post: 07-20-2008, 11:25 AM
  2. Your Screen Resolution/ Size
    By sandogg in forum Computers & Technology
    Replies: 42
    Last Post: 01-10-2008, 03:47 AM
  3. Full screen html pages on all screen sizes.
    By AZOVGY in forum Scripts & 3rd Party Apps
    Replies: 4
    Last Post: 10-21-2007, 06:25 AM
  4. Blank Screen
    By GFXEddie in forum Scripts & 3rd Party Apps
    Replies: 6
    Last Post: 09-15-2006, 03:29 PM
  5. MSN Screen Saver
    By MicrotechXP in forum Off Topic
    Replies: 1
    Last Post: 07-20-2005, 07:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers