简体   繁体   中英

Body Size and Stock Information Using simple_html_dom.php

First of all, thank you for your help.

I am using the simple_html_dom.php file. I get the product name, product description and product photos without any problem. I cannot get stock information in product size and size information. I need help.

Page Output: https://i.stack.imgur.com/0CaXf.png

if(!empty($linkler)){
$html='<table><tr><td>URUN_ADI</td><td>URUN_ACIKLAMA</td><td>URUN_FIYAT</td><td>SKU_KODU</td><td>URUN_FOTO</td></tr>';

foreach ($linkler as $link){
    if($tekLink = curl($link)){
        foreach($tekLink->find('div.product-details-container') as $e){
            $urunbaslik = $tekLink->find('h1',0)->innertext . '<br>';
            $urunacik   = $tekLink->find('div.full-description',0)->plaintext . '<br>';
            $bul        = array(' ', 'TL', ',');
            $degistir   = array('', '', '.');
            $fiyat      = str_replace($bul, $degistir, $tekLink->find("span[itemprop='price']",0)->plaintext);
            $sku        = $tekLink->find("span[itemprop='sku']",0)->plaintext;

            foreach($tekLink->find("img[itemprop='image']") as $f){
                $fotolar .= $f->src . ';';
            }

            $html.='<tr><td>'.$urunbaslik.'</td><td>'.$urunacik.'</td><td>'.$fiyat.'</td><td>'.$sku.'</td><td>'.$fotolar.'</td></tr>';
            $fotolar = '';
        }
    }
}
echo $fotolar;
$html.='</table>';
header('Content-Type:application/xls');
header('Content-Disposition:attachment;filename='.$parcalaURL[sizeof($parcalaURL)-2].'-'.date("d-m-Y H:i").'.xls');
echo $html;

}

i've voted to close this question as should be updated to include... the shortest code necessary to reproduce the problem. , because your post does not include the url nor the html you want to parse. nevertheless, from the screenshot you provided, getting the stock prices should be something like

$domd =new DOMDocument();
@$domd->loadHTML($html);
$xp=new DOMXPath($domd);
$stocks = [];
foreach($xp->query("//input[@name='product_attribute_9411']") as $stock){
    $stockName = $stock->parentNode->textContent;
    $stockValue = $stock->getAttribute("data-qty");
    $stocks[$stockName] = $stockValue;
}
var_dump($stocks);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM