John Davidson

need help extracting url from background-image in tag with simple_html_dom.php

0 comments
Message:


am new in the scrapping world, Like to know if some one know a way to extract background-image url from a Li tag. here I place the code from the original html page:
Thank in advace....


<li class="first b-loaded" 
data-puntuacion="6,3"
style="background-image: url(&quot;/carteles/255/primavera_en_beechwood_91776.jpeg&quot;);">



My Answer:
You can use simple_html_dom.php to extract the background-image URL from the li tag. Here is an example code snippet to achieve this:

php
include 'simple_html_dom.php';

$html = file_get_html('your_html_page.html');

foreach($html->find('li') as $li) {
$style = $li->style;
preg_match('/url\((.*?)\)/', $style, $matches);
$url = $matches[1];
echo $url;
}


This code will extract the background-image URL from all li tags in the HTML page. You can modify it to suit your specific requirements.

Rate this post

3 of 5 based on 4129 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us