Advertisement
Guest User

Untitled

a guest
Feb 24th, 2013
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. <?php
  2. require 'scraperwiki/simple_html_dom.php';
  3.  
  4. $allLinks = array();
  5. $counter = 0;
  6.  
  7. function nextPage($nextUrl){
  8. global $counter;
  9. getLinks($nextUrl);
  10.  
  11. }
  12.  
  13. function getLinks($url){ // gets links from product list page
  14. global $allLinks;
  15. global $counter;
  16.  
  17. $html_content = scraperwiki::scrape($url);
  18. $html = str_get_html($html_content);
  19.  
  20. foreach ($html->find("div.views-row a.imagecache-product_list") as $el) {
  21. $url = $el->href . "\n";
  22. $allLinks[$counter] = 'http://www.uptherestore.com';
  23. $allLinks[$counter] .= $url;
  24. $counter++;
  25. }
  26.  
  27. $next = $html->find("li.pager-next a", 0);
  28. if( $next != false ) $next = $next->href;
  29.  
  30. if (isset($next)) {
  31. $nextUrl = 'http://www.uptherestore.com';
  32. $nextUrl .= $next;
  33. nextPage($nextUrl);
  34. }else{return;}
  35.  
  36. }
  37.  
  38. class Product{ //Creates an object class for products
  39. public $name = '';
  40. public $infoLink = '';
  41. public $description = '';
  42. public $mainImage = '';
  43. public $moreImages1 = '';
  44. public $moreImages2 = '';
  45. public $moreImages3 = '';
  46. public $moreImages4 = '';
  47. public $price = '';
  48. public $designer= '';
  49. }
  50.  
  51.  
  52. function getInfo($infoLink){ // Trawls the product pages for info
  53.  
  54. $the_content = scraperwiki::scrape($infoLink);
  55. $the_html = str_get_html($the_content);
  56.  
  57. $productName = $the_html->find("#item_info h1", 0)->innertext;
  58.  
  59. $products[$productName] = new Product;
  60. $products[$productName]->name = $productName;
  61. $products[$productName]->infoLink = $infoLink;
  62. $products[$productName]->designer = $the_html->find("#item_info h2", 0)->innertext;
  63. $products[$productName]->description = $the_html->find("#item_info .product-body", 0)->innertext; //Might cause issues because there are multiple <p> tags in this div
  64. $products[$productName]->mainImage = $the_html->find("#item_image .imagecache-product_item_default", 0)->src;
  65.  
  66. $more1 = $the_html->find(".extra_images", 0);
  67. $more2 = $the_html->find(".extra_images", 1);
  68. $more3 = $the_html->find(".extra_images", 2);
  69. $more4 = $the_html->find(".extra_images", 3);
  70.  
  71. if (isset($more1)) {
  72. $products[$productName]->moreImages1 = $more1->src;
  73. }
  74. if (isset($more2)) {
  75. $products[$productName]->moreImages1 = $more2->src;
  76. }
  77. if (isset($more3)) {
  78. $products[$productName]->moreImages1 = $more3->src;
  79. }
  80. if (isset($more4)) {
  81. $products[$productName]->moreImages1 = $more4->src;
  82. }
  83. $products[$productName]->price = $the_html->find(".price", 0)->innertext;
  84.  
  85. // Store: $infoLink, $description, $mainImage, $moreImages, $price, $designer
  86. echo $products[$productName]->name . "\n";
  87. echo $products[$productName]->description . "\n";
  88.  
  89. }
  90.  
  91.  
  92.  
  93. getLinks("http://www.uptherestore.com/department/accessories");
  94.  
  95. foreach ($allLinks as $key => $value) {
  96. getInfo($value);
  97. }
  98.  
  99.  
  100. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement