抓取某些网站时file_get_contents 和 curl 都失效
我想抓取http://justcoding.iteye.com/ 这个博客的网页内容,使用了以下代码:
<?php
$baseurl = 'http://justcoding.iteye.com/';
$list = file_get_contents($baseurl);
//OR
$ch = curl_init();
$timeout = 10;
curl_setopt ($ch, CURLOPT_URL, $baseurl);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
$list = curl_exec($ch);
echo $list;
但是两个代码都无法获取博客内容,但是如果换成抓取google.com的话,就会成功。这个说明是justcoding.iteye.com博客屏蔽了file_get_contents 和 curl,如果是这样的话,还有什么方法可以抓取网页呢?
====================================================
我在本地测试是成功的,但是在我的godday的域名下不成功,那么原因是我的hosting的问题吗?我做的测试是,google,yahoo,qq,baidu这些都可以抓取,唯独iteye不可以。代码错误是:
Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/content/09/11850609/html/services/justcoding.php on line 34
请问为什么会这样?
sodgood
11 years, 7 months ago