欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

php采集頁(yè)面數(shù)據(jù)入庫(kù) php采集頁(yè)面數(shù)據(jù)入庫(kù)方法

如何用Php語(yǔ)言把網(wǎng)頁(yè)上的文章信息存入mysql數(shù)據(jù)庫(kù)的表中

首先,你是不是要做采集.如果是.你要會(huì)PHP的正則表達(dá)式,去獲取頁(yè)面文章的標(biāo)題,以及對(duì)應(yīng)的內(nèi)容,然后分別放到兩個(gè)變量中。再通過SQL 寫到數(shù)據(jù)庫(kù).

成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的玉樹網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

怎么用php采集網(wǎng)站數(shù)據(jù)

簡(jiǎn)單的分了幾個(gè)步驟:

1、確定采集目標(biāo)

2、獲取目標(biāo)遠(yuǎn)程頁(yè)面內(nèi)容(curl、file_get_contents)

3、分析頁(yè)面html源碼,正則匹配你需要的內(nèi)容(preg_match、preg_match_all),這一步最為重要,不同頁(yè)面正則匹配規(guī)則不一樣

4、入庫(kù)

PHP采集入庫(kù)問題

php 里有$nr = implode(‘#’,$arr) 方法 ,就可以 了

不過上面的組成的是“內(nèi)容1#內(nèi)容2”,沒有最后面的一個(gè)#,要是必須的話

就是$nr = implode('#',$arr).'#'

在笨的方法,就是用

foreach( $arr as $vl){

$nr.=$vl."#";

}

PHP獲取網(wǎng)站中的信息并存入數(shù)據(jù)庫(kù)

用PHP自帶函數(shù)就可以實(shí)現(xiàn),首先要過去對(duì)方的網(wǎng)頁(yè)信息,用

file_get_contents();參數(shù)是對(duì)方的URL地址,這個(gè)函數(shù)返回是一個(gè)字符串你想要的東西就在這個(gè)字符串中了

接下來就可以針對(duì)這個(gè)字符串做處理了,說下思路,正如你這個(gè)問題想獲取到航班號(hào)起飛時(shí)間,在這個(gè)網(wǎng)頁(yè)中應(yīng)該有很多相同的標(biāo)簽元素,它們都有共同點(diǎn),用

用正則表達(dá)式preg_match();或者是

preg_match_all();這兩個(gè)函數(shù)它們都返回一個(gè)數(shù)組,這個(gè)數(shù)組存的就是你要的航班號(hào)和起飛時(shí)間,那么相同信息的數(shù)組就會(huì)出現(xiàn)了,然后在對(duì)這個(gè)數(shù)組進(jìn)行分析找到你要的某個(gè)值或全部的值

獲取信息要用到的3個(gè)函數(shù)是:

file_get_contents();

preg_match();

preg_match_all();

抓取網(wǎng)頁(yè)數(shù)據(jù)怎么保存到數(shù)據(jù)庫(kù) php

給一個(gè)例子你看看吧.

if($pro_list_contents=@file_get_contents(''))

{

preg_match_all("/td width=\"50%\" valign=\"top\"(.*)td width=\"10\"img src=\"images\/spacer.gif\"/isU", $pro_list_contents, $pro_list_contents_ary);

for($i=0; $icount($pro_list_contents_ary[1]); $i++)

{

preg_match_all("/a href=\"(.*)\"img src=\"(.*)\".*span(.*)\/span/isU", $pro_list_contents_ary[1][$i], $url_img_price);

$url=addslashes($url_img_price[1][0]);

$img=str_replace(' ', '20%', trim(''.$url_img_price[2][0]));

$price=(float)str_replace('$', '', $url_img_price[3][0]);

preg_match_all("/a class=\"ml1\" href=\".*\"(.*)\/a/isU", $pro_list_contents_ary[1][$i], $proname_ary);

$proname=addslashes($proname_ary[1][0]);

include("inc/db_connections.php");

$rs=mysql_query("select * from pro where Url='$url' and CateId='{$cate_row['CateId']}'"); //是否已經(jīng)采集了

if(mysql_num_rows($rs))

{

echo "跳過:{$url}br";

continue;

}

$basedir='/u_file/pro/img/'.date('H/');

$save_dir=Build_dir($basedir); //創(chuàng)建目錄函數(shù)

$ext_name = GetFileExtName( $img ); //取得圖片后輟名

$SaveName = date( 'mdHis' ) . rand( 10000, 99999 ) . '.' . $ext_name;

if( $get_file=@file_get_contents( $img ) )

{

$fp = @fopen( $save_dir . $SaveName, 'w' );

@fwrite( $fp, $get_file );

@fclose( $fp );

@chmod( $save_dir . $SaveName, 0777 );

@copy( $save_dir . $SaveName, $save_dir . 'small_'.$SaveName );

$imgpath=$basedir.'small_'.$SaveName;

}

else

{

$imgpath='';

}

if($pro_intro_contents=@file_get_contents($url))

{

preg_match_all("/\/h1(.*)\/td\/tr/isU", $pro_intro_contents, $pro_intro_contents_ary);

$p_contents=addslashes(str_replace('src="', 'src="', $pro_intro_contents_ary[1][0]));

$p_contents=SaveRemoteImg($p_contents, '/u_file/pro/intro/'.date('H/')); //把遠(yuǎn)程html代碼里的圖片保存到本地

}

$t=time();

mysql_query("insert into pro(CateId, ProName, PicPath_0, S_PicPath_0, Price_0, Contents, AddTime, Url) values('{$cate_row['CateId']}', '$proname', '$imgpath', '$img', '$price', '$p_contents', '$t', '$url')");

echo $url.$img.$cate."br\r\n";

}

}

網(wǎng)站名稱:php采集頁(yè)面數(shù)據(jù)入庫(kù) php采集頁(yè)面數(shù)據(jù)入庫(kù)方法
標(biāo)題路徑:http://www.chinadenli.net/article16/dooijdg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化全網(wǎng)營(yíng)銷推廣小程序開發(fā)定制開發(fā)網(wǎng)站制作外貿(mào)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司