一个PHP类,它并行实现Curl来提取电子邮件地址
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一个PHP类,它并行实现Curl来提取电子邮件地址相关的知识,希望对你有一定的参考价值。
<a href="http://pantuts.com/2013/10/24/ayeemtract-using-curl-parallel/">http://pantuts.com/2013/10/24/ayeemtract-using-curl-parallel/</a>
<?php /** * AyeEmtract a class that crawls pages and * then searches for email addresses using curl in parallel. * * PHP version >= 5.x * * @category PHP * @author PANTUTS * @license http://www.gnu.org/licenses/gpl.txt * @link http://www.pantuts.com */ class AyeEmtract { // variable to store data // array of urls // addition curl options // errors /** * Creates object and store array of urls and additional options * * @param array $urls array of urls * @param array $options addition curl options */ { $this->_urls = $urls; $this->_options = $options; } /** * Sets curl_multi, curl options, and executes curl * per url. */ public function start() { // initialize curl multi handle // curl singles array // loop all urls foreach ($this->_urls as $i => $url) { // curl_init each url CURLOPT_SSL_VERIFYPEER => false, CURLOPT_USERAGENT => self::_setUserAgent(), CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 7, CURLOPT_CONNECTTIMEOUT => 20, CURLOPT_FRESH_CONNECT => true ) ); // check additional options } // now add multi handle } // execute multi handles $running = null; do { // save errors if encountered } } while ($running > 0); // get content on each url from curlh foreach ($curlh as $j => $ch) { // save results and remove handle } // close handle } /** * Returns array of emails * * @return array_unique(array) */ public function getEmails() { // regex to find valid emails $re = "/([\s]*)([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*([ ]+|)@([ ]+|)([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,}))([\s]*)/i"; foreach ($this->_results as $i => $res) { // decode htmlentities like %3C foreach ($matches[0] as $match) { // save to array found emails } } // remove duplicates } /** * Returns random user-agent * * @return $ua */ private static function _setUserAgent() { 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0', 'Mozilla/5.0 (Windows NT 6.2; rv:22.0) Gecko/20130405 Firefox/22.0', 'Opera/9.80 (J2ME/MIDP; Opera Mini/5.0 (Windows; U; Windows NT 5.1; en) AppleWebKit/886; U; en) Presto/2.4.15', 'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14', 'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))', 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1623.0 Safari/537.36', 'Mozilla/5.0 (X11; CrOS i686 4319.74.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36', 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2' ); return $ua; } } ?>
以上是关于一个PHP类,它并行实现Curl来提取电子邮件地址的主要内容,如果未能解决你的问题,请参考以下文章
在php 的curl函数来GET一个地址,得到的响应是一个json文件,怎么来操作这个文件