- 开发无止境 -
Data: 2017-01-12 10:15:00Form: JournalClick: 11
用php的curl抓取网页遇到了问题,为阐述方便,将代码简化如下:
代码的目的很简单,抓取页面:http://www.144go.com
执行上述代码,得到的结果:
HTTP/1.1 301 Moved Permanently
Content-Length: 144
Content-Type: text/html
Location: http://www.144go.com/
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Mon, 03 Sep 2012 04:25:22 GMT
<head><title>Document Moved</title></head>
<body><h1>Object Moved</h1>This document may be found <a HREF="http://www.144go.com/">here</a></body>
由结果中的
Location: http://www.144go.com/
可知http://144go.com被重定向到了http://www.144go.com/
怎么办呢,要用正则分析出Location部分的链接,重复执行执行curlGet吗?行到是行,就是有点麻烦。
其实只要加一条语就可以了: