ホームページ  >  記事  >  バックエンド開発  >  新浪ニュース Thief_PHP チュートリアル

新浪ニュース Thief_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-21 16:09:04949ブラウズ


新浪ニュース泥棒 1.





Sina_News クローラー ;



$host="127.0.0.1" // MYSQL ホスト名
$ namesql="????"; // MYSQL ユーザー名
$passsql="????"; // データベース名
$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==' <' and strlen($add) ==1){ $flag=0; }
if($word=='<' と strlen($add)!=1){ $add= substr($add,0,strlen( $add)-1); }
if($word=='>'){ $flag=1; } }

if($add,$keytop) { $found=1; (strchr($add,$keybottom)){ $found=0; $end=1; }
if(((strchr($add,'<')==True および strchr($add,'href') ==True) または strchr($add,'<')==False) および $found==1){ $text[$i]=$add; }
if($word=='< ;' と $flag==1){ $add=$word; $flag=0 } }
fclose($ fp); =1;$i$temp[1]=$text[$i+1]; $temp[2] =$text[$i+2] ; $temp[3]=$text[$i+3]; $temp[4]=$text[$i+4];
$ins="TITLE='$temp[3] から * を選択'";
$list=mysql_query($ins,$conn);
@$count=mysql_num_rows($list);
if($count==0){
$ins= "$table(TYPE,URL)に挿入,TITLE,DATE) 値 ('$temp[1]','$temp[2]','$temp[3]','$temp[4]')";
$list=mysql_query($ ins,$conn); } }
mysql_close($conn);
?>





2.$sign = 0;
while(!feof($handle))
{
$message = fgets( $handle,512);
if($sign == 1)
{
print("$message");
}
if(ereg("News Start",$message,$result))
{
$sign = 1; if(ereg("ニュース終了",$message,$result))
{
$sign = 0;
}
fclose($handle);



http://www.bkjia.com/PHPjc/314626.html

www.bkjia.com

tru​​e

http://www.bkjia.com/PHPjc/314626.html

技術記事

新浪ニュース泥棒 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="???????...

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。