php - PHP file_get_contents() 不工作并显示 gethostbyname failed 错误。如何解决?
问题描述
我想用 PHP 做一个简单的网络爬虫。我尝试过使用 file_get_contents()。但它不能正常工作。它显示如下错误。
Warning: file_get_contents(): php_network_getaddresses: gethostbyname failed. errno=0 in /storage/emulated/legacy/htdocs/search/crawl.php on line 12
Warning: file_get_contents(http://www.wikipedia.com): failed to open stream: php_network_getaddresses: gethostbyname failed. errno=0 in /storage/emulated/legacy/htdocs/search/crawl.php on line 12
Warning: implode(): Invalid arguments passed in /storage/emulated/legacy/htdocs/search/crawl.php on line 38
这是什么意思??第 12 行的代码也是
$mainUrl = "http://www.wikipedia.org";
$str = file_get_contents($mainUrl);
第 38 行的代码,
$all_links = implode(",",$sec_url);
那么现在如何解决这个问题?
解决方案
尝试使用 https 并确保在 php.ini 中允许:allow_url_fopen=1
$mainUrl = "https://samplesite.com";
$str = file_get_contents($mainUrl);
推荐阅读
- ios - 奇怪的行为设置 tableView 行高和 scrollPosition Swift
- node.js - 如何添加“原因”来禁止命令
- sql - 使用存储过程将查询结果插入表时出现问题
- python - numpy,用数组替换列
- postgresql - 如何避免postgresql备份内容回显到屏幕
- python - 尝试使用 RSA 加密视频帧;解密后得到垃圾而不是原始数据
- java - 在 android 6.0.1 中,为什么在通过相机拍照后尝试从 Uri 获取位图时为空?
- swift - vDSP_zrvmul 不返回任何结果(或全为零)
- javascript - 如何在里面使用js var或者
标签?
- python - pySpark forEachPartition - 代码在哪里执行