What is the problem with this code? Error:This page isnt working. it works without $post_str=file_get_contents($post_url->href); i test $post_url->href out of foreach with echo and it show url.it is not working only in file_get_contents please help me.
require_once("inc/simple_html_dom.php");
for($page_number=1;$page_number<=1;$page_number++) {
$page_url="https://songsara.net/page/{$page_number}";
$page_str=file_get_contents($page_url);
$page_base=new simple_html_dom();
$page_base->load($page_str);
foreach($page_base->find('.postbox-i') as $post) {
foreach($post->find('.post-img-hover a') as $post_url) {
echo "url: ".$post_url->href."</br>";
}
$post_str=file_get_contents($post_url->href);
$post_base=new simple_html_dom();
$post_base->load($post_str);
$track_index=1;
foreach($post_base->find('.audioplayer-tracklist .audioplayer-track-item .audioplayer-item-dl a') as $track_url) {
echo "->trackurl_{$track_index}: ".$track_url->href."</br>";
$track_index++;
}
}
}
Likeky $post_url->href
is a relative url, just prepend domain
try this one ...
error_reporting(E_ALL);
$base = 'your_url_here';
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $base);
curl_setopt($curl, CURLOPT_REFERER, $base);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$str = curl_exec($curl);
curl_close($curl);
// Create a DOM object
$html_base = new simple_html_dom();
// Load HTML from a string
$html_base->load($str);
//get all category links
foreach($html_base->find('a') as $element) {
echo "<pre>";
print_r( $element->href );
echo "</pre>";
}
$html_base->clear();
unset($html_base);