簡體   English   中英

警告:file_get_contents(): php.network_getaddresses: getaddrinfo

[英]Warning: file_get_contents(): php_network_getaddresses: getaddrinfo

我擁有一台專用服務器並安裝了 CENTOS 7 並安裝了 WEB 面板和 PHP 版本 8.1.13

在我嘗試創建一個簡單的 web 爬網腳本來運行之前,從過去 12 天開始一切都運行良好。

<?php
include ("simple_html_dom.php");
$html =file_get_html("https://www.bbc.com");
echo $html;

foreach($html-> find("div li") as $h)
{
    echo $h-> text();
}

?>

它給了我一個錯誤

Warning: file_get_contents(): php_network_getaddresses: getaddrinfo for www.bbc.com failed: Name or service not known in home/myserver/public_html/news/simple_html_dom.php on line 82

Warning: file_get_contents(https://www.bbc.com): Failed to open stream: php_network_getaddresses: getaddrinfo for www.bbc.com failed: Name or service not known in /home/myserver/public_html/news/simple_html_dom.php on line 82

Fatal error: Uncaught Error: Call to a member function find() on bool in home/myserver/public_html/news/tim.php:6 Stack trace: #0 {main} thrown in /home/myserver/public_html/news/tim.php on line 6

我還查找了服務器上的日志。 它也適用於許多其他域

在此處輸入圖像描述

為了找到解決方案,我查看了許多視頻教程並閱讀了幾篇文章。 據我所知,這個問題是由於 DNS 服務器端配置錯誤造成的。 我尋找解決方案,但沒有一個對我有用。 如果有人請指導我修復此 DNS 錯誤,我將不勝感激。

我已經檢查了服務器端的基本配置,對我來說看起來非常好。 此外,我非常謹慎地打破現有配置。

您的 IP 地址似乎被封鎖或臨時限制。 抓取過程比僅通過 file_get_contents 獲取數據要復雜得多。 你應該注意標題,cookies,也許是會話。 只是為了像普通用戶一樣。

此外,您可以使用公共 API。通常像 BBC 這樣的大型網站都會使用它來避免 HTTP 頻道的負載過大。 例如: https://apitracker.io/a/bbc-news

此外,您還可以訂閱 BBC 的 RSS 提要並通過它查看更新。 組織下載內容會更容易。 例如: https://gist.github.com/mburst/5230448

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM