新浪新聞小偷
更新時(shí)間:2006年10月09日 00:00:00 作者:
新浪新聞小偷 1.
<html>
<head>
<meta http-equiv="Refresh" content="60">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="Content-Type" content="text/html"; charset="??????">
<title>新浪_新聞抓取程序</title>
</head>
<body>
<center><img src="pic.gif"></center>
<?
$host="127.0.0.1"; // MYSQL 主機(jī)名
$namesql="????"; // MYSQL 用戶名
$passsql="????"; // MYSQL 密碼
$lib="news"; // 數(shù)據(jù)庫(kù)名
$table="news"; // 數(shù)據(jù)庫(kù)表名
$filename="http://news.sina.com.cn/news1000/index.shtml"; // 抓取的新聞頁(yè)
$keytop="新聞開(kāi)始"; // 新聞開(kāi)始關(guān)鍵詞
$keybottom="新聞結(jié)束"; // 新聞結(jié)束關(guān)鍵詞
$conn=mysql_connect($host,$namesql,$passsql);
mysql_select_db($lib,$conn);
$fp=fopen($filename,"r",1);
$flag=0; $add=""; $found=0; $end=0; $i=0; $temp[4]="";
while(!$end==1){
while(!$flag==1){
$word=fgetc($fp);
$add=$add.$word;
if($word=='<' and strlen($add)==1){ $flag=0; }
if($word=='<' and strlen($add)!=1){ $flag=1; $add=substr($add,0,strlen($add)-1); }
if($word=='>'){ $flag=1; } }
if(strchr($add,$keytop)){ $found=1; }
if(strchr($add,$keybottom)){ $found=0; $end=1; }
if(((strchr($add,'<')==True and strchr($add,'href')==True) or strchr($add,'<')==False) and $found==1){ $text[$i]=$add; $i++; }
if($word=='<' and $flag==1){ $add=$word; $flag=0; } else { $add=""; $flag=0; } }
fclose($fp);
for($i=1;$i<sizeof($text)-1;$i+=5){
$temp[1]=$text[$i+1]; $temp[2]=$text[$i+2]; $temp[3]=$text[$i+3]; $temp[4]=$text[$i+4];
$ins="select * from $table where TITLE='$temp[3]'";
$list=mysql_query($ins,$conn);
@$count=mysql_num_rows($list);
if($count==0){
$ins="insert into $table(TYPE,URL,TITLE,DATE) values ('$temp[1]','$temp[2]','$temp[3]','$temp[4]')";
$list=mysql_query($ins,$conn); } }
mysql_close($conn);
?>
</body>
</html>
2.<?
$handle = fopen("http://news.sina.com.cn/news1000/","r");
$sign = 0;
while(!feof($handle))
{
$message = fgets($handle,512);
if($sign == 1)
{
print("$message");
}
if(ereg("新聞開(kāi)始",$message,$result))
{
$sign = 1;
}
else if(ereg("新聞結(jié)束",$message,$result))
{
$sign = 0;
}
}
fclose($handle);
?>
相關(guān)文章
如何在PHP中使用Oracle數(shù)據(jù)庫(kù)(5)
如何在PHP中使用Oracle數(shù)據(jù)庫(kù)(5)...2006-10-10
php auth_http類庫(kù)進(jìn)行身份效驗(yàn)
前提是要安裝auth類庫(kù)和auth_http類庫(kù)2009-03-03
php學(xué)習(xí)筆記 數(shù)組的常用函數(shù)
只要一個(gè)變量,需要在多個(gè)方法使用,就將這個(gè)變量聲明為成員屬性,可以直接在這個(gè)對(duì)象中的所有方法中使用 成員屬性,相當(dāng)于這個(gè)對(duì)象中的全局變量2011-06-06
將OICQ數(shù)據(jù)轉(zhuǎn)成MYSQL數(shù)據(jù)
將OICQ數(shù)據(jù)轉(zhuǎn)成MYSQL數(shù)據(jù)...2006-10-10
Apache, PHP在Windows 9x/NT下的安裝與配置 (二)
Apache, PHP在Windows 9x/NT下的安裝與配置 (二)...2006-10-10
PHP的FTP學(xué)習(xí)(二)[轉(zhuǎn)自?shī)W索]
PHP的FTP學(xué)習(xí)(二)[轉(zhuǎn)自?shī)W索]...2006-10-10

