通過cURL來做小偷程式

來源:互聯網
上載者:User
本篇將會介紹通過cURL來做小偷程式。

<!-- 通過cURL來做小偷程式 -->

<?php   //如何請求、地圖等第三方API呢?   //這個時候就需要使用到——cURL。cURL中文翻譯過來叫做基於URL的函數庫。   //它的主要功能是:使用相關的函數類比協議請求。   //例如:   //1.類比表單向某個地址發送資料   //2.在無驗證碼的情況下類比表單完成使用者登入   //3.上傳某個檔案到遠程伺服器   //4.請求遠程伺服器提供的某些功能      //curl支援dict,file,ftp,ftps,gopher,http,https,imap,imaps,idap,idaps,   //pop3,pop3s,rtmp,rtsp,smtp,smtps,teInet和tftp協議。   //curl同時也支援HTTPS認證、HTTP的POST、HTT和PPUT、FTP上傳(這個   //也能通過PHP的FTP擴充完成)、HTTP基於表單的上傳、代理、cookies和使用者名稱+密碼的認證。 ?>    <!-- curl使用方法和步驟 --> <?php //1.初始化curl資源 //2.參數佈建要求的協議地址 //3.設定是否返回請求結果 //4.設定發送資料(無發送資料可不設定) //5.其他的參數資訊設定(按實際工作需要決定) //6.執行或執行得到返回結果 //7.關閉curl資源     $ch = curl_init();     curl_setopt($ch, CURLOPT_URL, "https://www.php.cn");     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);     curl_setopt($ch, CURLOPT_HEADER, 0);     $output = curl_exec($ch);     curl_close($ch);     print_r($output); ?>    <!-- curl 自訂get方法抓取網頁 --> <?php     $content = get('https://www.xmtnews.com/events');     preg_match('/<section class="ov">(.*?)<p class="hr-10"><\/p>/mis', $content,$match);     $area = $match[1];     preg_match_all('/<h3><a href="(.*?)" title=".*?"          class="headers" target="_blank">(.*?)<\/a><\/h3/>', $area, $find);     var_dump($find);     function get($find){         $ch = curl_init();         curl_setopt($ch, CURLOPT_URL, $url);         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);         curl_setopt($ch, CURLOPT_HEADER, 0);         curl_setopt($ch, CURLOPT_TIMEOUT, 10);         $output = curl_exec($ch);         curl_close($ch);     } ?>    <!-- curl使用post發送資料 --> <?php     function post($url, $data){         //初始化init方法         $ch = curl_init();         //指定URL         curl_setopt($ch, CURLOPT_URL, $url);         //佈建要求後返回結果         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);         //聲明使用POST方式來發送         curl_setopt($ch, CURLOPT_POST, 1);         //發送什麼資料呢         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);         //忽略認證         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);         //忽略header頭資訊         curl_setopt($ch, CURLOPT_HEADER, 0);         //設定逾時時間         curl_setopt($ch, CURLOPT_TIMEOUT, 10);         //發送請求         $output = curl_exec($ch);         //關閉curl         curl_close($ch);         //返回資料         return $output;     } ?>

本篇介紹了通過cURL來做小偷程式。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.