Advertisement
illpastethat

PHP craigslist start (in progress)

Jun 7th, 2014
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. <!DOCTYPE html>
  2.     <html lang="en">
  3.     <head>
  4.         <meta charset="utf-8"> 
  5.         <title>New Craigslist listings</title>
  6.         <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  7.         <link href='http://fonts.googleapis.com/css?family=Milonga' rel='stylesheet' type='text/css'>
  8.     </head>
  9.     <body>
  10.         <p>
  11.             <?php
  12.             $cities = array("washingtondc", "miami", "sfbay", "newyork", "losangeles", "sandiego"); #Craigslist subdomains
  13.            $keywords = array("web*", "wordpress", "site"); # What you want to search for...
  14.            $category = "cpg"; # Craigslist category key
  15.            
  16.             foreach ($cities as $city) {
  17.                 $link = "http://" . $city . ".craigslist.org" . "/" . $category;
  18.                 $dom = new DomDocument($link);
  19.                 @$dom->loadHTML($html);
  20.                 $urls = $dom->getElementsByTagName('a');
  21.                 foreach ($urls as $url) {
  22.                     $attributes = $url->attributes;
  23.                     echo "<br>$url->nodeValue is $attributes->href";
  24.                     ob_flush();
  25.                     flush();
  26.                     break;
  27.                 }
  28.             }
  29.             ob_end_flush();
  30.             ?>
  31.         </p>
  32.     </body>
  33. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement