v2.5.2
Giriş yap

simple_html_dom innertext sorunu

emmir2
280 defa görüntülendi

<?php

include 'class.php';

$html = file_get_html('http://eshop.erhanteknik.com.tr/urunlerimiz?categoryId=1');
?>

<?php 
foreach ($html->find('.product-image a') as $element){ ?>

<img src="<?php echo $element->find('img',0)->src; ?>" alt="">
<div><?php echo $element->find('.product-codenumber', 0)->innertext; ?></div>
<?php } ?>

aldığım hata
<b>Notice: Trying to get property 'innertext' of non-object in C:\xampp\htdocs\curl\index.php on line 12</b>

Cevap yaz
Cevaplar (3)
emmir2
492 gün önce

hocam normalde class ile çekebiliyorduk şuan ki olayı hiç algılayamadım

edit :

<?php
$html = file_get_html('http://eshop.erhanteknik.com.tr/urunlerimiz?categoryId=1');
$find = $html->find('.product-3 .clearfix');

if (count($find)) {
    foreach ($find as $item){ ?>
        <img src="<?= $item->find('img',0)->src; ?>" alt="">
        <div><?= $item->find('.product-codenumber',0)->plaintext; ?></div>
        <div><?= $item->find('.product-desc',0)->plaintext; ?></div>
    <?php }
}
?>

abdullahx
492 gün önce

Ben yaptığım olayı açıklayayım, siz kodunuzda .product-image altındaki bütün a elemanlarını alıyordunuz ama o elemanların arasında Sepete ekle butonunun a elemanları da vardı. Ben .product-image in sadece bir seviye altındaki a elemanlarını almak için > çocuk seçisini kullandım.
.product-codenumber elemanı da seçtiğimiz a elemanlarının dom ağacında içinde değil aynı seviyede iki eleman ötedeki kardeşleri konumunda olduğu için de next_sibling i iki defa kullanarak ulaştım

abdullahx
493 gün önce

Hiyerarşi ile ilgili ufak sorunların vardı

<?php
$html = file_get_html('http://eshop.erhanteknik.com.tr/urunlerimiz?categoryId=1');
$find = $html->find('.product-image > a');

if (count($find)) {
    foreach ($find as $item){ ?>
        <img src="<?= $item->find('img',0)->src; ?>" alt="">
        <div><?= $item->next_sibling()->next_sibling()->plaintext ?></div>
    <?php }
}