使用简单 HTML Dom 从 HTML 页面抓取数据

Scrape Data from HTML page using Simple HTML Dom

我是网络抓取的新手。我有一个 HTML 页面,我想从中抓取数据。我已经设法使用下面的代码

获取标题等数据
$name= $html->find('h1[class=page-title]', 0)->plaintext;

但现在我有一个 div 如下所示

<div class="company--performance-data">

          <div class="field field--name-field-stock-price-prev-close field--type-decimal field--label-above field__items">
      <div class="field__label">Previous trading day’s Close</div>
                <div content="61.58000" class="field__item">
        .58
            </div>
          </div>

          <div class="field field--name-field-stock-price-current-high field--type-decimal field--label-above field__items">
      <div class="field__label">Current high for the day</div>
                <div content="64.40000" class="field__item">
        .40
            </div>
          </div>

          <div class="field field--name-field-stock-price-current-low field--type-decimal field--label-above field__items">
      <div class="field__label">Current low for the day</div>
                <div content="62.78000" class="field__item">
        .78
            </div>
          </div>

          <div class="field field--name-field-days-volume field--type-decimal field--label-above field__items">
      <div class="field__label">Day's Volume</div>
                <div class="field__item">
        406
            </div>
          </div>

      
          <div class="field field--name-field-30-days-average-volume field--type-decimal field--label-above field__items">
      <div class="field__label">30 days average volume</div>
                <div content="0.553734" class="field__item">
        1
            </div>
          </div>

          <div class="field field--name-field-market-cap field--type-string field--label-above field__items">
      <div class="field__label">Market Cap</div>
                <div class="field__item">
        [=14=].00
            </div>
          </div>

          <div class="field field--name-field-stock-52-week-high field--type-decimal field--label-above field__items">
      <div class="field__label">52-week high</div>
                <div content="72.60" class="field__item">
        .60
            </div>
          </div>

          <div class="field field--name-field-stock-52-week-low field--type-decimal field--label-above field__items">
      <div class="field__label">52-week low</div>
                <div content="42.64" class="field__item">
        .64
            </div>
          </div>

          <div class="field field--name-field-stock-last-paid-div-value field--type-decimal field--label-above field__items">
      <div class="field__label">Last paid dividend value</div>
                <div content="0.47" class="field__item">
        [=14=].47
            </div>
          </div>

          <div class="field field--name-field-stock-dividend-yield field--type-decimal field--label-above field__items">
      <div class="field__label">Dividend Yield</div>
                <div content="3.03814" class="field__item">
        3.04%
            </div>
          </div>

          <div class="field field--name-field-stock-funds-from-operation field--type-decimal field--label-above field__items">
      <div class="field__label">Previous quarter FFO</div>
                <div content="217.76" class="field__item">
        7.76mil
            </div>
          </div>


      </div>

我想从中获取每个字段值,例如 $0.47。但由于它有 class 名称字段,我不知道如何从中获取价值。这里有人可以帮我吗?

非常感谢!

请试试这个:

foreach($html1->find("div.field__item") as $m)
{
    $txt = trim($m->plaintext);
    $attribute_array = $m->attr;
    if(isset($attribute_array['content']))
    {
        var_dump($attribute_array['content']);
    }
    var_dump($txt);
}