I am having trouble fetching content from a web-page,
actually i wanted to fetch all the inner text from div name displaybody
but my code doesn’t seems working, it is fetching all the content of the page instead of fetching the content from displaybody div and after 4 page successfully fetched i get an error,
Fatal error: Maximum execution time of 30 seconds exceeded in E:\Installations\xampp\htdocs\wp\simple_html_dom.php on line 127
Here is the code for the script,
I want my script to open all the sub-pages(/txt/any number) inside the url mentioned in the code and fetched the content from its particular div (displaybody)
<?php
$request_url ='http://www.zedge.net/txts/4519/200-3-1/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$regex='/href=\"\/txt\/[0-9].*/';
preg_match_all($regex,$result,$parts);
foreach($parts[0] as $link){
$url = 'http://zedge.net' . str_replace ("href=\"",'',$link);
echo file_get_html($url)->plaintext;
echo "<br /><br / ><br />";
}
curl_close($ch);
echo $html->find('displaybody', 0)->innertext;
?>
The error means your script is taking too long to execute, so it is shut down. If the fetching of the pages just takes a long time and this is no problem, you can disable or increase the max. execution time with
set_time_limit(). It’s also possible that a bug is causing your script to be stuck for too long on a single part, if you suspect this is the case you should measure the time at different parts of your script to see what’s causing the script to hang.As for your other issue, you want to get the
div#displaybodycontents from every individual page? Assuming the URL extraction is already working, I suppose you could do that by doing this inside theforeachloop: