Advertisement
SpeakeazyYT

Untitled

Jul 6th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. function getParamsXCom($articul)
  2. {
  3.   // подключаем страницу html товара
  4.   $_products = phpQuery::newDocument(file_get_contents('https://www.xcom-shop.ru/search/?o=n&s='.$articul));
  5.   $link = 'https://www.xcom-shop.ru' . $_products->find('div.wrap div.name a')->attr('href');
  6.   $detail_page = phpQuery::newDocument(file_get_contents($link));
  7.  
  8.   $arr = [];
  9.   foreach ($detail_page->find('#prop-columns .prop-line.delimiter') as $char) {
  10.     $category = pq($char);
  11.     $props = [];
  12.     $i = 0;
  13.  
  14.     // подобие функции .nextUntil в JQuery
  15.     foreach($category as $child) {
  16.       if($i == 2){ break; }
  17.       $i = (pq($child)->attr('class') == 'delimiter') ? ($i + 1) : $i;
  18.       if($i == 0){ continue; }
  19.      
  20.       foreach(pq($child) as $el) {
  21.         $props[$el->find('.call').text()] = $el->find('.prop-value')->text();
  22.       }
  23.     }
  24.    
  25.     $arr[$category->text()] = $props;
  26.   }
  27.  
  28.   print_r($arr);
  29. }
  30.  
  31. print_r(getParamsXCom('4YV96ES'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement