Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'scraperwiki/simple_html_dom.php';
- $allLinks = array();
- $counter = 0;
- function nextPage($nextUrl){
- global $counter;
- getLinks($nextUrl);
- }
- function getLinks($url){ // gets links from product list page
- global $allLinks;
- global $counter;
- $html_content = scraperwiki::scrape($url);
- $html = str_get_html($html_content);
- foreach ($html->find("div.views-row a.imagecache-product_list") as $el) {
- $url = $el->href . "\n";
- $allLinks[$counter] = 'http://www.uptherestore.com';
- $allLinks[$counter] .= $url;
- $counter++;
- }
- $next = $html->find("li.pager-next a", 0);
- if( $next != false ) $next = $next->href;
- if (isset($next)) {
- $nextUrl = 'http://www.uptherestore.com';
- $nextUrl .= $next;
- nextPage($nextUrl);
- }else{return;}
- }
- class Product{ //Creates an object class for products
- public $name = '';
- public $infoLink = '';
- public $description = '';
- public $mainImage = '';
- public $moreImages1 = '';
- public $moreImages2 = '';
- public $moreImages3 = '';
- public $moreImages4 = '';
- public $price = '';
- public $designer= '';
- }
- function getInfo($infoLink){ // Trawls the product pages for info
- $the_content = scraperwiki::scrape($infoLink);
- $the_html = str_get_html($the_content);
- $productName = $the_html->find("#item_info h1", 0)->innertext;
- $products[$productName] = new Product;
- $products[$productName]->name = $productName;
- $products[$productName]->infoLink = $infoLink;
- $products[$productName]->designer = $the_html->find("#item_info h2", 0)->innertext;
- $products[$productName]->description = $the_html->find("#item_info .product-body", 0)->innertext; //Might cause issues because there are multiple <p> tags in this div
- $products[$productName]->mainImage = $the_html->find("#item_image .imagecache-product_item_default", 0)->src;
- $more1 = $the_html->find(".extra_images", 0);
- $more2 = $the_html->find(".extra_images", 1);
- $more3 = $the_html->find(".extra_images", 2);
- $more4 = $the_html->find(".extra_images", 3);
- if (isset($more1)) {
- $products[$productName]->moreImages1 = $more1->src;
- }
- if (isset($more2)) {
- $products[$productName]->moreImages1 = $more2->src;
- }
- if (isset($more3)) {
- $products[$productName]->moreImages1 = $more3->src;
- }
- if (isset($more4)) {
- $products[$productName]->moreImages1 = $more4->src;
- }
- $products[$productName]->price = $the_html->find(".price", 0)->innertext;
- // Store: $infoLink, $description, $mainImage, $moreImages, $price, $designer
- echo $products[$productName]->name . "\n";
- echo $products[$productName]->description . "\n";
- }
- getLinks("http://www.uptherestore.com/department/accessories");
- foreach ($allLinks as $key => $value) {
- getInfo($value);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement