蛋疼的一下午,物理机win7旗舰版+APACHE2 ,CURL抓取一直成功。 虚拟机ubuntu+apache2一直抓取失败。

晚上,问个仁兄才知道,CURL可以调试: 参考这位兄台: 地址

curl_errno 和 curl_error 函数,分别返回 HTTP 的错误代码和错误类别。例如:

<?php
$ch = curl_init('http://www.soso.com/');
curl_exec($ch);
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
?> 返回: Curl error: couldn't connect to host

我嘞个去,无法连接www.soso.com 是怎么回事,DNS错误找不到IP?ping www.soso.com 也是OK的。 ping的通

$ch = curl_init('http://www.soso.com/');
curl_setopt($ch, CURLINFO_HEADER_OUT, true);//curl_getinfo 函数返回的数组将包含 cURL 请求的 header 信息
curl_setopt($ch, CURLOPT_HEADER , true);//回应的 header 信息
curl_exec($ch);
if (curl_errno($ch)) {
var_dump(curl_getinfo($ch));
var_dump('Curl error: ' . curl_error($ch));
}
curl_close($ch); 依旧是那些看不懂的信息一大堆: array(22) {
["url"]=>
string(20) "http://www.soso.com/"
["content_type"]=>
NULL
["http_code"]=>
int(0)
["header_size"]=>
int(0)
["request_size"]=>
int(0)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(0)
["redirect_count"]=>
int(0)
["total_time"]=>
float(63.127513)
["namelookup_time"]=>
float(2.0E-5)
["connect_time"]=>
float(0)
["pretransfer_time"]=>
float(0)
["size_upload"]=>
float(0)
["size_download"]=>
float(0)
["speed_download"]=>
float(0)
["speed_upload"]=>
float(0)
["download_content_length"]=>
float(-1)
["upload_content_length"]=>
float(-1)
["starttransfer_time"]=>
float(0)
["redirect_time"]=>
float(0)
["certinfo"]=>
array(0) {
}
["redirect_url"]=>
string(0) ""
}
string(36) "Curl error: couldn't connect to host"

最后,还是没办法。试一下wget 抓www.soso.com 我怀疑网络很有问题。

大概5分钟后,终于成功抓取到了一次www.soso.com页面。 5分钟啊,C.网络肯定有问题

路由追踪下:

root@ubuntu:~# tracepath www.soso.com
: 142.54.182.194 .071ms pmtu
: 142.54.182.193 .475ms
: 142.54.182.193 .468ms
: 192.187.107.125 .311ms
: 69.30.209.137 .598ms
: te0---.mpd22.mci01.atlas.cogentco.com .625ms
: be2141.ccr22.dfw01.atlas.cogentco.com .982ms
: be2032.ccr21.dfw03.atlas.cogentco.com .210ms
: 4.68.111.101 .825ms asymm
: vlan80.csw3.Dallas1.Level3.net .881ms asymm
: ae--.ebr3.Dallas1.Level3.net .135ms asymm
: ae--.ebr2.LosAngeles1.Level3.net .265ms asymm
: ae--.csw2.LosAngeles1.Level3.net .357ms
: ae--.edge6.LosAngeles1.Level3.net .118ms asymm
: 59.43.182.89 .536ms asymm
: 59.43.182.149 .360ms asymm
: 59.43.182.150 .715ms asymm
: 59.43.248.254 .674ms asymm
: 202.55.1.246 .871ms asymm
: no reply
: no reply
: no reply
: no reply
: no reply
: no reply
: no reply
: no reply
: no reply
: no reply
: no reply
: no reply
: no reply
: no reply
Too many hops: pmtu
Resume: pmtu

拿美国2台服务器跟踪路由试一下, 发现都是一模一样的 . 第18个开始失败, 但是另一台却可以正常CURL,和WGET. 卧槽,奇怪。

下个结论吧,SOSO BAIDU都有抓取频率限制。不过至少比SOGOU好多了,SOGOU根本不允许抓。

SOSO BAIDU抓取频率设置还是很高的,一般一秒抓一个我看都没事。 估计我的服务器IP已经被封了吧。心碎!

PHP CURL 抓取失败 自己调试的更多相关文章

  1. PHP使用CURL抓取网页

    CURL是一个非常强大的开源库,支持很多协议,包括HTTP.FTP.TELNET等,我们使用它来发送HTTP请求.它给我 们带来的好处是可以通过灵活的选项设置不同的HTTP协议参数,并且支持HTTPS ...

  2. php curl抓取远程页面内容的代码

    使用php curl抓取远程页面内容的例子. 代码如下: <?php /** * php curl抓取远程网页内容 * edit by www.jbxue.com */ $curlPost = ...

  3. shell用curl抓取页面乱码,参考一下2方面(转)

    1.是用curl抓取的数据是用类似gzip压缩后的数据导致的乱码.乱码:curl www.1ting.com |more乱码:curl -H "Accept-Encoding: gzip&q ...

  4. 使用file_get_contents()和curl()抓取网络资源的效率对比

    使用file_get_contents()和curl()抓取网络资源的效率对比 在将小程序用户头像合成海报的时候,用到了抓取用户头像对应的网络资源,那么抓取方式有很多,比如 file_get_cont ...

  5. 好用的 curl 抓取 页面的封装函数

    由于经常使用php curl 抓取页面的内容,在此mark 平时自己封装的 curl函数,(其实 现在也开始用 Python 来爬了~ ^-^) /** * 封装curl方法 * @author Fr ...

  6. 通过CURL抓取页面中的图片路径并下载到本地

    1.首页是图片处理页面downpic.php <?phpfunction getImage($url,$filename="") { if($url=="" ...

  7. curl抓取页面时遇到重定向的解决方法

    用php的curl抓取网页遇到了问题,为阐述方便,将代码简化如下: <?php function curlGet($url) { $ch = curl_init(); curl_setopt($ ...

  8. PHP用curl抓取网站数据,仿造IP、伪造来源等,防屏蔽解决方案教程

    1.伪造客户端IP地址,伪造访问referer:(一般情况下这就可以访问到数据了) curl_setopt($curl, CURLOPT_HTTPHEADER, ['X-FORWARDED-FOR:1 ...

  9. PHP cURL抓取网上图片

    cURL的底层是由一个命令行工具实现的,用于获取远程文件或传输文件,更多的情况是用来模拟get/post表单提交.也可以用户文件上传,爬取文件,支持FTP/FTPS,HTTP/HTTPS等协议,通俗来 ...

随机推荐

  1. php PDO mysql

    php PDO写法连接mysql: $db=new PDO("mysql:host=localhost;dbname=sql","root","roo ...

  2. C#-流、存储

    流输入输出 VS提供的类库,可方便数据的转移操作,一部分是文件和目录方面 file类 用静态方法,   fileinfo类 用实例方法   dictionary类 用静态方法   dictionary ...

  3. (线段树)Balanced Lineup --POJ --3264

    链接: 对于POJ老是爆,我也是醉了, 链接等等再发吧! http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82832#problem/G 只 ...

  4. 关闭父类弹出的ifream窗口

    parent.document.getElementById('zhuce').style.display = 'none';

  5. hdu 5066 小球碰撞(物理题)

    http://acm.hdu.edu.cn/showproblem.php?pid=5066 中学物理题 #include <cstdio> #include <cstdlib> ...

  6. hdu 5014 异或序列

    http://acm.hdu.edu.cn/showproblem.php?pid=5014 从最大的一个数开始找能配对使他们的异或值最大的一个数 最后输出 #include <cstdio&g ...

  7. 洛谷P3066 [USACO12DEC]逃跑的Barn (线段树合并)

    题目描述It's milking time at Farmer John's farm, but the cows have all run away! Farmer John needs to ro ...

  8. 集合(三)CopyOnWriteArrayList

    第一次见到CopyOnWriteArrayList,是在研究JDBC的时候,每一个数据库的Driver都是维护在一个CopyOnWriteArrayList中的,为了证明这一点,贴两段代码,第一段在c ...

  9. Oracle EBS打补丁

    http://hutianci.iteye.com/blog/1457287 l例子: 打 Patch#   11843100:R12.CAC.B 打PATCH之前先查询一下是否已经有了这个PATCH ...

  10. C#基础复习(1) 之 Struct与Class的区别

    参考资料 [1] 毛星云[<Effective C#>提炼总结] https://zhuanlan.zhihu.com/p/24553860 [2] <C# 捷径教程> [3] ...