PHP網頁抓取之抓取百度貼吧郵箱資料代碼分享

來源:互聯網
上載者:User
百度貼吧大家都經常逛,去逛百度貼吧的時候,經常會看到樓主分享一些資源,要求留下郵箱,樓主才給發。

對於一個熱門的文章,留下的郵箱數量是非常多的,樓主需要一個一個的去複製那些回複的郵箱,然後再粘貼發送郵件,不是被折磨死就是被累死。無聊至極寫了一個抓取百度貼吧郵箱資料的程式,需要的拿走。

程式實現了一鍵抓取文章全部郵箱和分頁抓取郵箱兩個功能,介面懶得做了,效果如下:

老規矩,直接貼源碼

<?php$url2="";$page="";if($_GET['url2']==""){$url2="http://tieba.baidu.com/p/2314539885?pn=1";}else{$url2=$_GET['url2'];}if($_GET['page']==""){$page="1";}else{$page=$_GET['page'];}?><?phpif($_GET['type']!=""){$counts=0;if($_GET['type']=="getAll"){$pages=$_GET['page'];$url = $_GET['url'];for($i=0;$i<$pages;$i++){$ch2 = curl_init();curl_setopt($ch2, CURLOPT_URL, $url);curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, TRUE);curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, FALSE);curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch2, CURLOPT_RETURNTRANSFER, TRUE);$texts = curl_exec($ch2);curl_close($ch2);$dat=getEmail($texts);for($j=0;$j";$counts++;}}}else if($_GET['type']=="getNow"){$url = $_GET['url2'];$ch2 = curl_init();curl_setopt($ch2, CURLOPT_URL, $url);curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, TRUE);curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, FALSE);curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch2, CURLOPT_RETURNTRANSFER, TRUE);$texts = curl_exec($ch2);curl_close($ch2);$dat=getEmail($texts);for($i=0;$i";$counts++;}}echo '

共採集到資料:'.$counts.'條

';}function getEmail($str){$pattern = "/([a-z0-9\-_\.]+@[a-z0-9]+\.[a-z0-9\-_\.]+)/"; preg_match_all($pattern,$str,$emailArr); return $emailArr[0]; }?>
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.