gpt4 book ai didi

php - PHP-无法打开流: no such host is known

转载 作者:行者123 更新时间:2023-12-03 07:46:45 25 4
gpt4 key购买 nike

嗨,我在简单的html dom代码中有一个问题,它显示此错误:-

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



因为这个网址 http://www.arakne-links.c现在无法正常运作

知道有什么方法可以跳过无法正常工作的网址。

这是我正在使用的代码
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;

请帮助我解决此问题。

谢谢

最佳答案

在解析之前检查URL怎么样?

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 "<br />";
} else {
echo 'Error: URL '.$value.' doesn\'t exist.<br />';
}
}
endforeach;
?>

关于php - PHP-无法打开流: no such host is known,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16358169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com