简体   繁体   English

PHP SimpleHTMLDOM:如何通过另一个div内的类名从div获取值?

[英]PHP SimpleHTMLDOM : how to get value from div by class name inside of another div?

i have following HTML snippet: 我有以下HTML代码段:

<div class="price-box szczeg_oper">
            <div class="row">
              <div class="col c-1-2 c-xs-1-1">
                <div class="price netto">cena: 11.30 <span class="currency">CZK</span></div>                <div class="ad_koszyk row">
          <div class="col c-1-2 c-xs-1-2">
            <div class="quantity lng_cz">        
              <label>množství</label>
              <input type="text" size="1" id="quantity_178" name="quantity" value="1" data-cip-id="quantity_178">
            </div>
          </div>
          <div class="col c-1-2 c-xs-1-2">
            <input type="hidden" name="parametersValue" value="">
            <input class="button pull-right" name="przyciskz" type="submit" value="Do košíku" onclick="ajax_cart_add(178, jQuery('#quantity_178').val(), 'cz', 0.115); return false;">
          </div>
         </div>              </div>
              <div class="col c-1-2 c-xs-1-1">
                                <div class="product-availability">Zboží je k dispozici na skladě</div>
              </div>
            </div>
          </div>

I'm trying to get value inside the 我试图在内部获得价值 div. div。

Div with same class is contained in the document a few times. 文件中包含相同类别的Div几次。 So i need to get only this one inside of the div 所以我只需要在div内放入一个

If i tried this: 如果我尝试这样做:

 //GET NETTO PRICE
    foreach($html->find('div[class=price-box szczeg_oper]') as $element){
        $itemPrice = $element->plaintext;
    }

I got text of whole div. 我得到整个div的文本。

How can i access into inner elements inside of the found div by class? 如何按类访问找到的div内部的内部元素?

I tried to find solution in documentation, but without luck: 我试图在文档中找到解决方案,但是没有运气:

http://simplehtmldom.sourceforge.net/manual.htm http://simplehtmldom.sourceforge.net/manual.htm

Many thanks for any advice 非常感谢您的任何建议

I'm assuming you're after the price 我想你是在追价

foreach($html->find('div[class=price-box szczeg_oper]') as $element){
    $itemPrice = $element->find('.price',0)->plaintext;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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