The basic principle of curl
Curl is an open source file transfer tool that uses URL syntax to work in the command line mode. It can download from the Internet Get a variety of network resources on the Internet. Simply put, curl is an upgraded version of crawling pages.
1
2
3
4
5
6
7
8
9
10
11
12
|
//1. Initialize and create a new cURL resource $ch = curl_init(); //2. Set URL and corresponding options curl_setopt( $ch , CURLOPT_URL, "http://www.baidu.com/" ); curl_setopt( $ch , CURLOPT_HEADER, 0); //3. Grab the URL and pass it to the browser curl_exec( $ch ); //4. Close cURL resources and release system resources div>
curl_close( $ch ); ?> |
cURL crawls the page Of crawling web page information and replacing
1
2
3
4
5
6
7
8
|
$curlobj = curl_init(); // Initialization curl_setopt( $curlobj < code class="php plain">, CURLOPT_URL, "http://www.baidu.com" ); // Set the URL to visit the webpage curl_setop t( $curlobj , CURLOPT_RETURNTRANSFER, true); / / Do not print directly after execution $output =curl_exec( $curlobj ); // Execute< /code> curl_close( $curlobj ); // Close curl echo str_replace ( "Baidu" , "php" , $output ); < code class="php plain">?>
|
< /p>
cURL crawling page to get the weather
1 div>
2
3
4
5
6
7
8 < /div>
9
10
11
12
13
14
< div class="line number15 index14 alt2"> 15 16
17
18
19
20
21
22
|
header( "Content-Type:text/html; charset=utf-8" ); $data = 'theCityName=Beijing' ; $curlobj = curl_init(); < /div>
curl_setopt( $curlobj , CURLOPT_URL, "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName" ); curl_setopt( $curlobj , CURLOPT_USERAGENT, "user-agent:Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Firefox /24.0" ); curl_setopt( code> $curlobj , CURLOPT_HEADER, 0); //When enabled, the header file information will be output as a data stream. Not enabled here curl_setopt( $curlobj code> , CURLOPT_RETURNTRANSFER, 1); //If successful, only the results will be returned, and nothing will be output automatically. If it fails, return FALSE curl_setopt( $curlobj< /code> curl_setopt( $curlobj < code class="php plain">, CURLOPT_POSTFIELDS, $data ); //Data that needs POST curl_setopt( $curlobj , CURLOPT_HTTPHEADER, array (" application/x-www-form-urlencoded; >charset=utf-8 ", " Content-length: ". strlen ( $data ))); $rtn = curl_exec( $curlobj );< /code> if (!curl_errno( < code class="php variable">$curlobj )){ // $info = curl_getinfo($curlobj); // print_r($info); echo $rtn ; } else { echo 'Curl error:' . curl_error( $curlobj < code class="php plain">); } curl_close( $curlobj ); ?> |
Original post address: https://www.cnblogs.com/laomao666 /p/10952235.html
1
2
3
4
5
6
7
8
9
10
11
12
|
//1. Initialize, create a new cURL Resources $ch = curl_init(); //2. Set the URL and corresponding options curl_setopt( $ch , CURLOPT_URL, "http://www.baidu.com/" ); curl_setopt( $ch , CURLOPT_HEADER, 0); //3. Grab the URL and pass it to the browser < code class="php plain">curl_exec( $ch ); //4. Close cURL resources and release system resources curl_close( $ch ); ?> |
< /p>
1
2
3
4
5
6
7
8
9
10
11
12
|
//1. Initialize and create a new cURL resource < code class="php variable">$ch = curl_init(); //2. Set URL and corresponding options curl_setopt( $ch , CURLOPT_URL, code> "http://www.baidu.com/" ); curl_setopt( $ch , CURLOPT_HEADER, 0); < code class="php comments">//3. Grab the URL and pass it to the browser
curl_exec( $ch ); //4. Close cURL resources and release system resources curl_close( $ch ); ?> |
< p>1
2
3
4
5
6
7
8
9
10
11
12
< /code> //1. Initialize and create a new cURL resource
$ch
= curl_init();
// 2. Set the URL and corresponding options
curl_setopt (
$ch
, CURLOPT_URL,
"http:// www.baidu.com/"
);
curl_setopt(
$ch
< code class="php plain">, CURLOPT_HEADER, 0); //3. Grab the URL and Pass it to the browser
curl_exec(< /code> $ch
);
//4. Close cURL resources and release system resources< /code>
curl_close(
$ch
);
?>
< /code> //1. Initialize and create a new cURL resource
$ch
= curl_init();
//2. Set the URL and corresponding options
curl_setopt(
$ch
, CURLOPT_URL,
"http://www.baidu.com/"
);
curl_setopt(
$ch< /code>
, CURLOPT_HEADER, 0);
//3. Grab the URL and pass it to Browser
curl_exec(
$ch
);
//4. Close cURL resources and release system resources< /code>
curl_close(
$ch< /code>
);
?>
1
2
3
4
5
6
< div class="line number7 index6 alt2"> 7 8
|
$curlobj = curl_init(); // Initialization curl_setopt( $curlobj , CURLOPT_URL,< /code> curl_setopt( $curlobj , CURLOPT_RETURNTRANSFER, true); // Do not print out directly after execution $output =curl_exec( $curlobj ); // Execute curl_close( $curlobj ); // Close cURL echo str_replace ( "Baidu" , "php" , $output < code class="php plain">); ?> div> |
1
2
3
4
5
6
7
8
|
$curlobj = curl_init(); // Initialization curl_setopt( $curlobj , CURLOPT_URL, "http://www.baidu.com" ); // Set the URL to visit the webpage curl_setopt( $curlobj , CURLOPT_RETURNTRANSFER, true ); $output< /code> curl_close( $curlobj ); // Close curl echo str_replace ( < code class="php string">"Baidu" , "php" , $out put ); ?> |
1
2
3 p>
4
5
6
7
8
$curlobj
code> = curl_init();
// Initialization