Hi i have a issue in simple html dom code it show this error :-
file_get_contents(http://www.arakne-links.com)
[function.file-get-contents]: failed to open stream:
php_network_getaddresses: getaddrinfo failed: No such host is known.
in D:\xampp\htdocs\scrap\simple_html_dom.php on line 75
because this url http://www.arakne-links.c is not working now i want
to know is there any way to skip the url which is not working..
here is the code which i am using
ini_set('display_errors', 'on');
include_once('../../simple_html_dom.php');
// create HTML DOM
$htmls = file_get_html('http://info.vilesilencer.com/top');
foreach($htmls->find('a[rel="nofollow"]') as $e):
$test = $e->href;
$url = array( $test );
$html = array();
foreach( $url as $key=>$value ) {
// get html plain-text for webpage & assign to html array.
$html = file_get_html( trim($value) );
// echo html plain text:
echo $html->find('title', 0)->innertext;
}
endforeach;
Please Help me to fix this issue.
Thankyou
Answer
How about checking the URL before parsing?
ini_set('display_errors', 'on');
include_once('simple_html_dom.php');
function urlOk($url) {
$headers = @get_headers($url);
if($headers[0] == 'HTTP/1.1 200 OK') return true;
else return false;
}
// create HTML DOM
$htmls = file_get_html('http://info.vilesilencer.com/top');
foreach($htmls->find('a[rel="nofollow"]') as $e):
$test = $e->href;
$url = array( $test );
$html = array();
foreach( $url as $key=>$value ) {
// get html plain-text for webpage & assign to html array.
if (urlOk(trim($value))) {
$html = file_get_html( trim($value) );
echo $html->find('title', 0)->innertext;
echo "
";
} else {
echo 'Error: URL '.$value.' doesn\'t exist.
';
}
}
endforeach;
?>
No comments:
Post a Comment