【发布时间】:2012-06-24 11:48:16
【问题描述】:
在包含简单的 HTML DOM 库时,我收到了警告:
警告:file_get_contents() [function.file-get-contents]:php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。在 C:\xampp\htdocs\simple_html_dom.php 第 70 行
警告:file_get_contents(http://www.google.com/) [function.file-get-contents]:无法打开流:php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。在 C:\xampp\htdocs\simple_html_dom.php 第 70 行
simple_html_dom.php文件(从http://sourceforge.net/projects/simplehtmldom/files/latest/download下载)第70行是
$contents = file_get_contents($url, $use_include_path, $context, $offset);
还有 1 个错误:
致命错误:在第 15 行调用 C:\xampp\htdocs\domdoc2.php 中非对象的成员函数 find()
代码的第 15 行(下)是
foreach($html->find('img') as $element)
我在下面的代码中引用的网页是 google.com 代码如下:
<?php
include('simple_html_dom.php');
$html = new simple_html_dom();
$html = file_get_html('http://www.google.com/');
// Find all images
foreach($html->find('img') as $element)
echo $element->src . '<br>';
// Find all links
foreach($html->find('a') as $element)
echo $element->href . '<br>';
?>
我做错了什么??
【问题讨论】:
-
这不是库问题,PHP 只是无法将主机解析为 IP 地址
-
@Baszz 你指的是哪个文件? DOM 文件在那里,它也包括在内
-
@user1458514 查看您的 Internet Explorer 代理设置
标签: php simple-html-dom