Heim  >  Artikel  >  Backend-Entwicklung  >  新浪新闻小偷_PHP教程

新浪新闻小偷_PHP教程

WBOY
WBOYOriginal
2016-07-21 16:09:04949Durchsuche


新浪新闻小偷 1.






新浪_新闻抓取程序



新浪新闻小偷_PHP教程


$host="127.0.0.1"; // MYSQL 主机名
$namesql="????"; // MYSQL 用户名
$passsql="????"; // MYSQL 密码
$lib="news"; // 数据库名
$table="news"; // 数据库表名
$filename="http://news.sina.com.cn/news1000/index.shtml"; // 抓取的新闻页
$keytop="新闻开始"; // 新闻开始关键词
$keybottom="新闻结束"; // 新闻结束关键词

$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=='if($word=='if($word=='>'){ $flag=1; } }

if(strchr($add,$keytop)){ $found=1; }
if(strchr($add,$keybottom)){ $found=0; $end=1; }
if(((strchr($add,'if($word=='fclose($fp);

for($i=1;$i$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);
?>






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("新闻开始",$message,$result))
{
$sign = 1;
}
else if(ereg("新闻结束",$message,$result))
{
$sign = 0;
}
}
fclose($handle);
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/314626.htmlTechArticle新浪新闻小偷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="?????...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn