Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我如何刮内联css?_Php_Scrape - Fatal编程技术网

Php 我如何刮内联css?

Php 我如何刮内联css?,php,scrape,Php,Scrape,我使用简单的html dom脚本从站点获取信息 我试图刮去一个携带显示的元素:none属性 以下是要素: <label data-product-attribute-value="1307" class="form-label" for="attribute_1307" style="display: none;">This is the title</label> $links->oute

我使用简单的html dom脚本从站点获取信息

我试图刮去一个携带显示的元素:none属性

以下是要素:

<label data-product-attribute-value="1307" class="form-label" for="attribute_1307" style="display: none;">This is the title</label>
$links->outertext仅提供以下内容:

<label data-product-attribute-value="1307" class="form-label" for="attribute_1307">This is the title</label>
您可以看到,它在刮片时不包括style属性

那么如何获得内联CSS属性呢?如果我必须使用不同的库,请建议。

您可以使用->style获得样式。试试这个:

foreach ($html->find('.form-label') as $links) {
   echo ($links->style); //op : display: none;
}

如我所料,这对我来说是可行的:

<?php
$html = <<< HTML
<label data-product-attribute-value="1307" class="form-label" for="attribute_1307" style="display: none;">
This is the title
</label>
HTML;

$dom = new DOMDocument;
$dom->loadHTML($html);
echo (   $label->hasAttribute('style')
      && preg_match('/display:\s*none/', $label->getAttribute('style')) ) ?
    "display set to 'none'" : "display NOT set to 'none'";

谢谢你的建议。我发现file_get_html也没有获取特定标签的style属性。我得到了一些元素的样式属性,但不是所有元素。我还使用curl通过URL删除所有HTML,但同样的问题也会出现。请建议。
<?php
$html = <<< HTML
<label data-product-attribute-value="1307" class="form-label" for="attribute_1307" style="display: none;">
This is the title
</label>
HTML;

$dom = new DOMDocument;
$dom->loadHTML($html);
echo (   $label->hasAttribute('style')
      && preg_match('/display:\s*none/', $label->getAttribute('style')) ) ?
    "display set to 'none'" : "display NOT set to 'none'";
display set to 'none'