cURL crawls the page to crawl the web page information and replace it

Replace page information

<?php
$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($curlobj);        // 关闭cURL
echo str_replace("百度","php",$output);
?>

We will change Baidu to PHP in the crawled Baidu page. The previous chapter was viewed under DOS. In this section, we directly use PHP to parse and view it.

Open on the web page, the effect is as follows

QQ截图20161105164650.png

In this way, we have completed the replacement of the obtained page content.

Continuing Learning
||
<?php $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($curlobj); // 关闭cURL echo str_replace("百度","php",$output); ?>
submitReset Code