CURL scratch page

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.

share picture

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

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

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> , CURLOPT_POST, 1); //If you want PHP to do a regular HTTP POST, set this option to one Non-zero value. This POST is a normal application/x-www-from-urlencoded type, which is mostly used by HTML forms.
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> "http://www.baidu.com" ); // Set the URL to access the webpage
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">);
?>

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 ); // Do not print out directly after execution
$output< /code> =curl_exec( $curlobj ); < code class="php comments">//Execute
curl_close( $curlobj ); // Close curl
echo str_replace ( < code class="php string">"Baidu" , "php" , $out put );
?>

1

2

3

4

5

6

7

8

$curlobj

code> = curl_init(); // Initialization

curl_setopt( $curlobj , CURLOPT_URL,  "http://www.baidu.com" );       // 设置访问网页的URL
curl_setopt( $curlobj , CURL OPT_RETURNTRANSFER, true);          // 执行之后不直接打印出来
$output =curl_exec( $curlobj );    // 执行
curl_close( $curlobj );         // 关闭cURL
echo  str_replace ( "百度" , "php" , $output );
?>

$curlobj  = curl_init();           // 初始化

curl_setopt( $curlobj , CURLOPT_URL,  "http://www.baidu.com" );       // 设置访问网页的URL

curl_setopt( $curlobj , CURLOPT_RETURNTRANSFER, true);          // 执行之后不直接打印出来

$output =curl_exec( $curlobj );    // 执行

curl_close( $curlob j );         // 关闭cURL

echo  str_replace ( "百度" , "php" , $output );

?>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
header( "Content-Type:text/html;   charset=utf-8" );
$data  ‘theCityName=北京‘ ;
$curlobj  = curl_init();
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( $curlobj , CURLOPT_HEADER, 0);           //启用时会将头文件的信息作为数据流输出。这里不启用
curl_setopt( $curlobj , CURLOPT_RETURNTRANSFER, 1);   //如果成功只将结果返回,不自动输出任何内容。如果失败返回FALSE
curl_setopt( $curlobj , CURLOPT_POST, 1);             //如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。
curl_setopt( $curlobj , CURLOPT_POSTFIELDS,  $data );   //需要POST的数据
curl_setopt( $curlobj , CURLOPT_HTTPHEADER,  array ("application/x-www-form-urlencoded;  
                                                     charset=utf-8 ", " Cont ent-length: ". strlen ( $data )));
$rtn  = curl_exec( $curlobj );
if (!curl_errno( $curlobj )){
     // $info = curl_getinfo($curlobj);
     // print_r($info);
     echo  $rtn ;
else  {
     echo  ‘Curl error: ‘  . curl_error( $curlobj );
}
curl_close( $curlobj );
?>

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
header( "Content-Type:text/html;   charset=utf-8" );
$data  ‘theCityName=北京‘ ;
$curlobj  = curl_init();
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( $curlobj , CURLOPT_HEADER, 0);           //启用时会将头文件的信息作为数据流输出。这里不启用
curl_setopt( $curlobj , CURLOPT_RETURNTRANSFER, 1);   //如果成功只将结果返回,不自动输出任何内容。如果失败返回FALSE
curl_setopt( $curlobj , CURLOPT_POST, 1);             //如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。
curl_setopt( $curlobj , CURLOPT_POSTFIELDS,  $data );   //需要POST的数据
curl_setopt( $curlobj , CURLOPT_HTTPHEADER,  array ("application/x-www-form-urlencoded;  
                                                     charset=utf-8 ", " Content-length: ". strlen ( $data )));
$rtn  = curl_exec( $curlobj );
if (!curl_errno( $curlobj )){
     // $info = curl_getinfo($curlobj);
     // print_r($info);
     echo  $rtn ;
else  {
     echo  ‘Curl error: ‘  . curl_error( $curlobj );
}
curl_close( $curlobj );
?>

 

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

header( "Content-Type:text/html;   charset=utf-8" );
$data  ‘theCityName=北京‘ ;
$curlobj  = curl_init();
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( $curlobj , CURLOPT_HEADER, 0);           //启用时会将头文件的信息作为数据流输出。这里不启用
curl_setopt( $curlobj , CURLOPT_RETURNTRANSFER, 1);   //如果成功只将结果返回,不自动输出任何内容。如果失败返回FALSE
curl_setopt( $curlobj , CURLOPT_POST, 1);             //如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。
curl_setopt( $curlobj , CURLOPT_POSTFIELDS,  $data );   //需要POST的数据
curl_setopt( $curlobj , CURLOPT_HTTPHEADER,  array ("application/x-www-form-urlencoded;  
                                                     charset=utf-8 ", " Content-length: ". strlen ( $data )));
$rtn  = curl_exec( $curlobj );
if (!curl_errno( $curlobj )){
     // $info = curl_getinfo($curlobj);
     // print_r($info);
     echo  $rtn ;
else  {
     echo  ‘Curl error: ‘  . curl_error( $curlobj );
}
curl_close( $curlobj );
?>

header( "Content-Type:text/html;   charset=utf-8" );

$data  ‘theCityName=北京‘ ;

$curlobj  = curl_init();

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( $curlobj , CURLOPT_HEADER, 0);           //启用时会将头文件的信息作为数据流输出。这里不启用

curl_setopt( $curlobj , CURLOPT_RETURNTRANSFER, 1);   //如果成功只将结果返回,不自动输出任何内容。如果失败返回FALSE

curl_setopt( $curlobj , CURLOPT_POST, 1);             //如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。

curl_setopt( $curlobj , CURLOPT_POSTFIELDS,  $data );   //需要POST的数据

curl_setopt( $curlobj , CURLOPT_HTTPHEADER,  array ("application/x-www-form-urlencoded;  

                                                     charset=utf-8 ", " Content-length: ". strlen ( $data )));

$rtn  = curl_exec( $curlobj );

if (!curl_errno( $curlobj )){

     // $info = curl_getinfo($curlobj);

     // print_r($info);

     echo  $rtn ;

else  {

     echo  ‘Curl error: ‘  . curl_error( $curlobj );

}

curl_close( $curlobj );

?>

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 519 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.