Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. function checkPrice($url)
  2. {
  3.     global $SKUS;
  4.     global $amazonURLS;
  5.     global $urls;
  6.     $price = 0;
  7.    
  8.     if(strpos($url, 'homedepot.com') !== false)   // Home Depot
  9.     {  
  10.     $dom = file_get_html($url, false);
  11.        
  12.     $element = $dom->find('span#ajaxPrice.pReg',0);
  13.        
  14.         if(!isset($element))
  15.         {
  16.             $price = 0;
  17.             return $price;
  18.         }
  19.         if(isset($element))
  20.         {
  21.             $price = $element->content;
  22.             $price = strtok($price, "$");  //idk the best way to do this in PHP so lets do this
  23.             $priceFloat = floatval($price);
  24.         }
  25.     }
  26.     else if(strpos($url, 'amazon.com') !== false)    //### Amazon, currently returning var_dump $DOM as NULL, some scraping protection?
  27.                                                     // Might have to try cURL library and set user agent with curl_setopt() and CURLOPT_USERAGEN
  28.                                                     // Follow redirects with CURLOPT_FOLLOWLOCATION -- Just an idea,
  29.     {
  30.         $dom = file_get_html($url, false);
  31.        
  32.        
  33.         $element = $dom->find('span#newBuyBoxPrice.a-size-base',0);
  34.        
  35.             echo $element . "test";
  36.        
  37.    
  38.         if(null === $element->content)
  39.         {
  40.            // echo "FAILED";
  41.             $price = 0;
  42.             return false;
  43.         }
  44.         if(null !== $element-content)
  45.         {
  46.             $price = $element->content;
  47.             $price = strtok($price, "$");  
  48.             $priceFloat = floatval($price);
  49.            
  50.         }
  51.     }
  52.  
  53. return $priceFloat;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement