Example of using PHP curl to capture the page after 302 jump_PHP tutorial

WBOY
Release: 2016-07-13 10:26:36
Original
812 people have browsed it

PHP’s CURL normal crawling page procedure is as follows:

$url = 'http://www.baidu.com';

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_VERBOSE, true); 
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 20); 
curl_setopt($ch, CURLOPT_AUTOREFERER, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
$ret = curl_exec($ch); 
$info = curl_getinfo($ch); 
curl_close($ch);

Copy after login


If you grab a 302 status, it is because during the crawling process, some jumps need to pass parameters to the next link, and the next link is also set. If the corresponding parameters are not received, it is an illegal access. .

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
Copy after login

The display should be normal.

The above is used to grab the function, which should be almost no problem. You can check CURLOPT_CUSTOMREQUEST related information.

Use a custom request message instead of "GET" or "HEAD" for the HTTP request. This is useful for performing "DELETE" or other more covert HTTP requests. Valid values ​​are "GET", "POST", "CONNECT", etc. That is, don't enter the entire HTTP request here. For example, entering "GET /index.html HTTP/1.0rnrn" is incorrect.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824641.htmlTechArticlePHP's CURL normal crawling page procedure is as follows: $url = 'http://www.baidu.com' ;$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_seto...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!