• 13-05-2021, 18:21:47
    #1
    Merhabalar,

    $stok = $tekLink->find('ul.radio-list',0)->innertext . '<br>';
    $xml = new DOMDocument();
    $xml->loadHTML($stok);
    $result = array();
    
    foreach($xml->getElementsByTagName('li') as $li) {
    foreach($li->getElementsByTagName('a') as $links){
    $result[] = $links->nodeValue;
    }
    }
    Her li döngüsünde inputlar var, fakat her inputun valu değeri farklı. Bu random id değerine rağmen valuden nasıl seçerim elemanları?





    Şimdiden teşekkürler.
  • 13-05-2021, 20:05:28
    #2
    Merhabalar burdan tam olarak neyi seçmek istiyorsunuz tam anlayamadım kullanıcı birtanesini seçecek onu mu alacaksınız öyle birşeyde ul li yerine selectbox kullanmanızı tavsiye ederim eder hepsini seçecekseniz bunu js ile mi almak istiyorsunuz yoksa post edip PHP ile yakalamak mı istiyorsunuz biraz açıklarsanız ona göre yardımcı olmaya çalışalım
  • 13-05-2021, 20:08:24
    #3
    product attributes i tutmak istiyorum fakat herseferinde farklı değer döndürmekte.Sondaki ID değeri.
  • 13-05-2021, 20:15:58
    #4
    $name = $tekLink->find('ul.radio-list',0)->find('li input',0)->name;

    bu şekilde alıp işleyebilirsiniz?
  • 16-05-2021, 12:49:15
    #5
    Cycl0ne adlı üyeden alıntı: mesajı görüntüle
    $name = $tekLink->find('ul.radio-list',0)->find('li input',0)->name;

    bu şekilde alıp işleyebilirsiniz?
    Hocam oradaki beden isimlerini ve data-qty de kalan stok sayısını okumaya çalışıyorum fakat erişemedim dataya.
  • 16-05-2021, 17:27:37
    #6
    (double) str_replace(',', '.', $node->getAttribute('data-qty'))
    $dom = new DomDocument();
    @$dom->loadHTML($stok);
    $xpath = new DOMXpath($dom);
    $nodes = $xpath->query("//ul[@class='radio-list']//li//input");
    
    $array = array();
    
    foreach ($nodes as $node) {
        array_push($array, array(
            'label' => $node->nextSibling->nodeValue,
            'name' => $node->getAttribute('name'),
            'value' => $node->getAttribute('value')
        ));
    }
    
    
    exit(json_encode($array));

    Alternatif;

    header('Content-type: application/json');
    $buffer = file_get_contents('link');
    $buffer = str_replace(array("\t", "\r", "\n"), '', $buffer);
    $buffer = str_replace('> <', '><', $buffer);
    $buffer = str_replace('  ', '', $buffer);
    $buffer = str_replace('> <', '><', $buffer);
    $buffer = str_replace("\" />", "\"/>", $buffer);
    
    // Ürün Kategori
    preg_match('#<span itemprop="name">(.+?)</span>#si', $buffer, $match);
    $category = $match[1];
    
    // Ürün Adı
    preg_match('#<h1 itemprop="name">(.+?)</h1>#si', $buffer, $match);
    $title = $match[1];
    
    // Ürün Açıklama
    $description = explode('<div class="accordion-item accordion-fulldescription active"><div class="full-description" itemprop="description">', $buffer);
    $description = explode('</div><span class="accordion-title" data-target="accordion-reviews">Yorumlar</span>', $description[1]);
    $description = $description[0];
    
    // Ürün Fotoğrafları
    $swiper = explode('<div class="swiper-master gallery-thumbs"><div class="swiper-wrapper">', $buffer);
    $swiper = explode('</div><div class="swiper-master gallery-top">', $swiper[1]);
    $swiper = $swiper[0];
    
    $images = array();
    
    preg_match_all('#<img itemprop="image" src="(.+?)" alt="(.+?)" title="(.+?)"/>#si', $swiper, $matches);
    foreach ($matches[1] as $index => $src) {
        array_push($images, array(
            'src' => $src,
            'alt' => $matches[2][$index],
            'title' => $matches[3][$index]
        ));
    }
    
    // Beden Tablosu
    $sizes = explode('<ul class="radio-list">', $buffer);
    $sizes = explode('</ul>', $sizes[1]);
    $sizes = $sizes[0];
    $sizes = trim(str_replace("</li>", "</li>\n", $sizes));
    
    $array = array();
    
    foreach (explode("\n", $sizes) as $node) {
        $beden = $adet = NULL;
    
        preg_match('/data-qty="([0-9]+),0000"/i', $node, $match);
        $adet = $match[1];
    
        preg_match('/<label for="(.+?)">(.+?)<\/label>/i', $node, $match);
        $beden = $match[2];
    
        array_push($array, array(
            'beden' => $beden,
            'adet' => $adet
        ));
    }
    
    // Yapısal Veri
    $data = array(
        'title' => $title,
        'description' => $description,
        'images' => $images,
        'category' => $category,
        'size' => $array
    );
  • 17-05-2021, 11:21:28
    #7
    @QuarkChain; arkadaşıma yardımlarından dolayı teşekkürler sorunum çözülmştür.