M
M
maxsharun2019-12-19 18:11:27
PHP
maxsharun, 2019-12-19 18:11:27

Why is the site fragment not being parsed?

I am writing a function to quickly add products by link in manual mode. Link example
https://www.sima-land.ru/2742033/nabor-bumagi-dlya...
You need to parse characteristics. Actually, charvals, charnames, and even separately manufacture are not parsed through the function. Checked the regex here: https://regex101.com/ . All regular seasons are working (there). But the function doesn't work. Here is the result of my work: xn----7sbbrc1bbojpqdj3d8de.xn--p1ai/api/parse?url=...
Tell me , what could be the reason and how can I better parse these characteristics? Thank you
Everything works

function simaland($url) {
    
      $out = array();
      $out = file_get_contents($url);
      
      
      if(preg_match_all('/<h1 itemprop="name">(.*?)<\/h1>/', $out, $pname))
      {
        $return['pname'] = $pname[1][0];
      }
      
      if(preg_match_all('/<meta itemprop="price" content="(.*?)">/', $out, $price))
      {
        $return['cost_price'] = $price[1][0];
      }
      
      if(preg_match_all('/<meta itemprop="priceCurrency" content="(.*?)">/', $out, $currency))
      {
        $return['currency'] = $currency[1][0];
      }
      
      if(preg_match_all('/<span class="b-properties__value">по (.*?) шт<\/span>/', $out, $min_order))
      {
        $return['min_order'] = $min_order[1][0];
      }
      
      if(preg_match_all('/data-large="(.*?)"/', $out, $images))
      {
        $return['images'] = $images[1];
      }
      
      $return['manufacture'] =array();
      if(preg_match_all('/<div class="_1KJXA">Торговая марка<\/div><\/div><div class="_3MM0w"><a href="[^>]+?[^>]+" target="_self" class="[^>]+?[^>]+"><span class="[^>]+?[^>]+">(.*?)<\/span><\/a>/im', $out, $mnf))
      {
        $return['manufacture'] = $mnf[1];
      }
      
      $return['charnames'] =array();
      if(preg_match_all('/<div class="_1KJXA">(.*?)<\/div>/m', $out, $charnames))
      {
        $return['charnames'] = $charnames[1];
      }
      
      $return['charvars'] =array();
      if(preg_match_all('/<div class="_1KJXA">(.*?)<\/div>/m', $out, $charvars))
      {
        $return['charvars'] = $charvars[1];
      } 
      
      
      
      if(preg_match_all('/<a class="link link_dark-blue no-visited popup_positioner" href="[^>]+?[^>]+">(.*?)<\/a>/', $out, $categories))
      {
        $return['categories'] = $categories[1];
      }
      
      
      return $return;
    
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-12-19
@maxsharun

class="_1KJXA"And what does the part with . mean in your regular expressions ? Strange naming

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question