loop php to scrap all items in a div

Solutions on MaxInterview for loop php to scrap all items in a div by the best coders in the world

showing results for - "loop php to scrap all items in a div"
Giovanni
13 Oct 2017
1require('simple_html_dom.php');
2 
3// Website link to scrap
4$website = 'http://www.example.com';
5 
6// Create DOM from URL or file
7$html = file_get_html($website);
8 
9// Find content of a div with class = 'xyz'
10$divData = $html->find('div[class=xyz]');
11 
12// Loop through divData and grab all the links present in it
13foreach ($divData as $key => $value) {    
14    $links = $value->find('a');
15    foreach ($links as $link) {
16        $linkHref = $link->href;
17        $linkText = $link->plaintext;
18    }    
19}
20