B
B
Berkutman2020-04-29 12:35:09
PHP
Berkutman, 2020-04-29 12:35:09

How to infer style from div when parsing DOM?

<div class="_img" style="background-image: url(&quot;https://example.com/image.jpg&quot;); width: 100%; height: 100%; max-width: 100%; max-height: 100%; border-radius: 0px;"></div>


How to get the style from the _img class and take only the background-image url from there?
I use phpsimple
At the moment, the code, unfortunately, does not display anything.
include_once('config/phpsimple/simple_html_dom.php');
$html = file_get_html('https://example.com/index.html');
 foreach($html->find('div._img') as $element) {
echo $element = $html->getAttribute('style');
 }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rickkk, 2020-04-29
@Rickkk

Do just var_dump($element) like this

foreach($html->find('div._img') as $element) {
var_dump($element);
}

and see if a key with style value is present in the $attr property of this $element object. Or in some other property. If not, then the problem is in the library. The library does not read inline styles on dom elements.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question