<?php
//1:curl初始化
 $ch = curl_init();
//2:设置post数据
 $data = array (
'post_xuehao' => '13110572068'
);
//3:设置请求的url
curl_setopt($ch, CURLOPT_URL, "http://210.44.176.116/cjcx/xhcx_list.php");
//4:设置请求的参数
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
//保存到文件,以注释
// $fop=fopen("test.html", "wr");
// if(!$fop){
// mkdir("test.html","wr");
// }
// curl_setopt($ch, CURLOPT_FILE,$fop);
//5:执行url,返回结果
$re=curl_exec($ch);
//6:打印到浏览器
echo $re;
//关闭curl
curl_close($ch);
// fclose($fop);
?>
Because in recent development, it is often necessary to use crawler technology to crawl website information. Here, because I don’t want to learn a new language too much, I use the php I have already mastered as the background crawler. Script, I heard that python is quite good, but that’s just a hearsay. Anyway, I’ve used it and it’s not very satisfying. However, no matter what language, the basic principle is the same. Here I use the curl tool to crawl, pay special attention to it. The thing is, you must turn on the curl extension of php, otherwise it cannot be used. I remember that in the php5.4.3 version, there was an unsolvable bug that curl could not be used. On Linux, the relevant extensions can now be used. The following is the specific example code:
The above introduces the use of PHP's curl to crawl the information after login, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.
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