Answers for "loop php to scrap all items in a div"

PHP
0

loop php to scrap all items in a div

require('simple_html_dom.php');
 
// Website link to scrap
$website = 'http://www.example.com';
 
// Create DOM from URL or file
$html = file_get_html($website);
 
// Find content of a div with class = 'xyz'
$divData = $html->find('div[class=xyz]');
 
// Loop through divData and grab all the links present in it
foreach ($divData as $key => $value) {    
    $links = $value->find('a');
    foreach ($links as $link) {
        $linkHref = $link->href;
        $linkText = $link->plaintext;
    }    
}
Posted by: Guest on April-03-2021

Code answers related to "loop php to scrap all items in a div"

Browse Popular Code Answers by Language