Advertisement
Guest User

Untitled

a guest
May 25th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 KB | None | 0 0
  1. Here is script how you do it with phpquery.
  2.  
  3.    
  4.  
  5.     <?php
  6.      
  7.     header("Content-type: text/csv");
  8.     header("Content-Disposition: attachment; filename=file.csv");
  9.     header("Pragma: no-cache");
  10.     header("Expires: 0");
  11.      
  12.     include_once 'phpquery.php';
  13.      
  14.     $html = file_get_contents("http://www.tpos.co.uk/search-results.php?city=london&postcode=&submit=Search");
  15.     $csv = "";
  16.      
  17.     $doc = phpQuery::newDocumentHTML($html);
  18.     phpQuery::selectDocument($doc);
  19.      
  20.      
  21.     foreach (pq("#member-list li") as $item){
  22.             $fax=$phone=$website="";
  23.            
  24.             $name = trim(pq($item)->find(".col-1 strong")->eq(0)->html());
  25.             $details = pq($item)->find("span.details")->html();
  26.             $tmp = explode("<br>",$details);      
  27.             $address = trim($tmp[0]);
  28.            
  29.             foreach ($tmp as $key=>$t){            
  30.                     if (strpos($t, "Fax")!==false){
  31.                             $fax = str_replace("Fax:","",trim(strip_tags($t)));
  32.                     }
  33.                     elseif (strpos($t, "Phone")!==false){                  
  34.                             $phone = str_replace("Phone:","",trim(strip_tags($t)));
  35.                     }
  36.                     elseif (strpos($t, "Website")!==false){                
  37.                             $url = str_replace("Website:","",trim(strip_tags($t)));
  38.                     }
  39.             }      
  40.      
  41.             $csv .= "{$name};{$address};{$phone};{$fax};{$url}\n";
  42.     }
  43.      
  44.     echo $csv;
  45.      
  46.     ?>
  47.  
  48. It is impossible to get city from address because sometimes address includes extra commas.
  49.  
  50. And here is the result file: https://mega.co.nz/#!nVIn2TJb!T9Q8IAOBnCxQeZ3byKTbSCb5Pz9WhbcvBlmwzMFq3Tk
  51.  
  52. Doing everything for my first Thanks on BHW :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement