我们要偷的是 myrice 的笑话
主程序
我们要偷的是 myrice 的笑话
主程序
  
@set_time_limit(0);
require_once('./db_mysql.php');
$DB_naps = new DB_Sql();
$DB_naps->database = "wapshow";
$DB_naps->connect("localhost", "root", "", 1);
/*
儿童篇 =1
夫妻篇 =2
古代篇 =3
爱情篇 =4
医疗篇 =5
家庭篇 =6
政治篇 =7
电脑篇 =8
军事篇 =9
经营篇 =10
体育篇 =11
司法篇 =12
交通篇 =13
宗教篇 =14
文艺篇 =15
鬼话篇 =16
校园篇 =17
名人篇 =18
交往篇 =19
愚人篇 =20
民间篇 =21
综合篇 =22
幽默篇 =24
英语篇 =25
原创篇 =26
动物篇 =27
*/
$sort = "2";
$page = 69;
for ($j = 2; $j <= $page; $j++) {
        
        $url = "http://joke.myrice.com/class/class_xhxhxh0".$sort."_".$j.".html";
$html = naps_get_html($url, "66.19.33.134:80");
        $pattern = "'javascript\:MM_openBrWindow\([\']?(.*?\.html)[\']?'si";
        if (preg_match_all($pattern, $html, $matches, PREG_SET_ORDER))
        {
                foreach ($matches as $value)
                {
                        $file_url = "http://joke.myrice.com".$value[1];
                        $file_html = naps_get_html($file_url, "66.119.33.134:8000");
                        $start_pos = strpos($file_html,"");
                        $end_pos   = strpos($file_html,"");
                        $title = "";
                        for ($i = $start_pos + strlen(""); $i < $end_pos; $i++) {
                                   $title .= $file_html{$i};
                        }
                        if (strlen($title) < 1) break;
                        $body = preg_match("'
$text = $mf[1];
if (strlen($text) < 10) break;
$DB_naps->query("INSERT INTO `joke` ( `id` , `title` , `texts` , `sortid` ) VALUES ('', '".addslashes($title)."', '".addslashes($text)."', '".$sort."')");
echo " ".$title." 入库完成!
";
flush();
}
} else {
echo " 没有匹配数据!
";
flush();
}
echo "第 $j 页完成!
";
flush();
}
echo " 夫妻篇完成!
";
flush();
?>
naps_get_html 函数
如果你使用 PEAR的类等得 也可以换别的函数 总之这个函数返回 远程取得的数据
function naps_get_html($url, $proxy = "", $proxyuser = "", $proxypsw = "", $limittime = "")
{ 
        if (function_exists(curl_init)) {
                
                if (empty($limittime) || ($limittime == "")) {
                        $limittime = 0;
                }
                
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_TIMEOUT, $limittime);
                
                if (!empty($proxy)) curl_setopt($ch, CURLOPT_PROXY,$proxy);
                if (!empty($proxyuser)) curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$proxyuser:$proxypsw");
                
                curl_setopt($ch, CURLOPT_NOBODY, 0);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);                
                $result = curl_exec($ch);
                if ($result == NULL) { 
           echo "Error:
";
           echo curl_errno($ch) . " - " . curl_error($ch) . "
";
                }
                curl_close($ch);
                
                return $result;
        } else {
                $fp = @fopen($url, 'rb');
                if ($fp) {
                        do {
                                $urldata = @fread($fp, 8192);
                            if (strlen($urldata) == 0) break;
                                    $result .= $urldata;
                                } while(true);
                        return $result;
                } else {
                        return false;
                }
        }
}
如果你的 空间支持 CURL 那么你可以使用 代理!
不支持CURL的 建议使用PEAR的 HTTP/Request.php包,它不使用CURL支持代理
db_mysql.php 程序
我就不提供了 用的是 VBB的 程序!
大家也可以 使用直接连接的!
在建立一个数据库 
CREATE TABLE `joke` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `title` varchar(250) NOT NULL default '',
  `texts` text NOT NULL,
  `sortid` int(5) NOT NULL default '0',
  UNIQUE KEY `id` (`id`)
) TYPE=MyISAM;
直接入库就好了 !
