V
V
Vladimir2019-01-22 22:20:25
PHP
Vladimir, 2019-01-22 22:20:25

PHP simple HTML DOM can't get attribute value, don't understand where is the error?

Please help,
5c476cc2b419a432341536.jpeg
I can't get the value of the attribute

$urlYear = 'https://razmerkoles.ru/size/peugeot/308/2013/';
      // print(getCurlResult($urlYear));
      // $file = fopen("5.txt", "w");
      // fwrite($file, getCurlResult($urlYear));
      // fclose($file);
      $html3 = str_get_html(getCurlResult($urlYear));			
      $htmlArr3 = $html3->find('#vehicle-market-data .vehicle-market'); // массив внутренних рынков
      if(count($htmlArr3) != 1) {// проверка есть ли разделения на внутренние рынки
        foreach ($htmlArr3 as $key => $div) {
          // echo $div->outertext . "<br>";
          $market = $html3->find('#vehicle-market-data .vehicle-market h4', $key)->plaintext; // выводит название внутреннего рынка
          echo $market . "<br>" . $urlYear . "<br>";
          foreach ($div->find('.modification-item') as $modifications) { // проходит по модификациям модели на одном рынке
            // echo "<pre>";
            // var_dump($modifications);
            // echo "</pre>";
            
            foreach ($modifications->find('tbody tr') as $k => $size) {
              // print($size->outertext . "<br>");
              $b = $size->attr['data-rim'];
              //->attr['data-rim']
              echo "<pre>";
              var_dump($b);
              echo "</pre>";
              
              // $file = fopen($k . ".txt", "w");
              // fwrite($file, $size->outertext);
              // fclose($file);

              $zz++;
              if($zz > 3) {
              exit;
              }
            }


          }
          
        }
        
      } else { //если нет разделения на внутренние рынки

      }

      $html3->clear(); // подчищаем за собой
      unset($html3);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
2
2cha.headz, 2019-01-23
L

If I'm not mistaken, then with this you go through all the tr's, and you are trying to take the attribute from them

foreach ($modifications->find('tbody tr') as $k => $size) {
...
}

You probably need something like this:
foreach ($modifications->find('tbody tr') as $k => $size) {
    $span = $size->find('.data-rim span')[0];
    print_r($span->attr['data-rim']);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question