javascript - Broken images in simple HTML dom -
i using simple_html_dom.php library fetch required elements page www.lifehacker.com when fetch images images don't appers , links looks broken. code using
<html> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script> <script type="text/javascript"> $(document).ready(function(){ $("p").click(function(){ $(this).hide(); }); }); $(document).ready(function(){ $("h1").click(function(){ $(this).hide(); }); }); $(document).ready(function(){ $("a").click(function(){ $(this).hide(); }); }); $(document).ready(function(){ $("img").click(function(){ $(this).hide(); }); }); $(document).ready(function(){ $("href").click(function(){ $(this).hide(); }); }); </script> <style type="text/css"> br{ display: none; } </style> </head> <body style="margin: 0 auto;max-width:900px; border:1px solid; padding:20px; margin-top:20px; "> <?php include_once('simple_html_dom.php'); $html = file_get_html('http://www.lifehacker.com/'); foreach($html->find('.icon') $item) { $item->outertext = ''; } $html->save(); foreach($html->find('br') $item) { $item->outertext = ''; } $html->save(); $title = $html->find('title',0)->innertext; $title = '<h1>'.$title.'<h1>'; echo $title; $html=$html->find('h1 , h2 , h3 ,img, p'); foreach($html $elements){ foreach($elements->find('a') $element) { if (isset($element->href)) { $element->href = null; } } foreach($elements->find('br') $element){ if(isset($element->br)){ $element->br=null; } } echo $elements.'<br>'; } ?> </body> </html>
this images of broken urls image
Comments
Post a Comment