Home  >  Article  >  Backend Development  >  curl in php captures web page response data

curl in php captures web page response data

小云云
小云云Original
2018-03-21 14:08:002089browse

This article mainly shares with you the method of using curl to capture web page response data in PHP. I hope it can help you.

 $val ) {


	         $aPOST [] = $key . "=" . urlencode ( $val );


	      }


	      $strPOST = join ( "&", $aPOST );


	   }


	   curl_setopt ( $oCurl, CURLOPT_URL, $url );


	   curl_setopt ( $oCurl, CURLOPT_RETURNTRANSFER, 1 );


	   curl_setopt ( $oCurl, CURLOPT_POST, true );


	   curl_setopt ( $oCurl, CURLOPT_POSTFIELDS, $strPOST );
	   
	   
	 //   curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false);// 过滤htpts
	 //   curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);// 过滤htpts
	 //   $UserAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; .NET CLR 3.5.21022; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
		// curl_setopt($oCurl, CURLOPT_USERAGENT, $UserAgent); // 使用代理
		// //
		// curl_setopt($oCurl, CURLOPT_HEADER, false);


		// curl_setopt($oCurl, CURLOPT_HEADER, 0);
     	
  		curl_setopt($oCurl, CURLOPT_COOKIEFILE, $cookie_file);


	   $sContent = curl_exec ( $oCurl );


	   $aStatus = curl_getinfo ( $oCurl );


	   curl_close ( $oCurl );


	   if (intval ( $aStatus ["http_code"] ) == 200) {


	      return $sContent;


	   } else {

	      return false;

	   }

	}
}

Related recommendations:

How to obtain CURL request headers and response headers in php

Detailed explanation of CURL for PHP web crawlers

CURL in php gets request headers and response headers

The above is the detailed content of curl in php captures web page response data. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn