代码如下 |
复制代码 |
function getsourcecode($q){ return @file_get_contents($q); } //用curl获取网站源文件 function c_getpagecode($c_url,$p_i=0){ $user_agent = "mozilla/4.0"; $proxy[0] = "http://211.155.231.208:80"; //浙江省杭州市 电信idc机房 $proxy[1] = "http://210.51.10.197:8888"; //北京市 通泰大厦网通idc机房 $ch = curl_init(); curl_setopt ($ch, curlopt_proxy, $proxy[$p_i]); curl_setopt ($ch, curlopt_url, $c_url); curl_setopt ($ch, curlopt_useragent, $user_agent); //curl_setopt ($ch, curlopt_cookiejar, "c:cookie.txt"); curl_setopt ($ch, curlopt_header, 0); curl_setopt ($ch, curlopt_returntransfer, 1); curl_setopt ($ch, curlopt_followlocation, 1); curl_setopt ($ch, curlopt_timeout, 120); $result = curl_exec ($ch); curl_close($ch); return $result; } |
//实例应用
代码如下 |
复制代码 |
$url ='http://mb.phprm.com'; //$body = getsourcecode( $url); |
//echo $body; //就把mb.phprm.com内容全部采集到了本地
//再来看一下用curl获取网站http://www.phprm.com文件函数实例
echo c_getpagecode($url);
教程网址:http://www.phprm.com/code/33775.html
欢迎收藏∩_∩但请保留本文链接。