你可以先把數(shù)據(jù)庫數(shù)據(jù)讀到一個數(shù)組里面,比如下面的語句:

創(chuàng)新互聯(lián)成立于2013年,先為長子等服務(wù)建站,長子等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為長子企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
$sql='select number from vote';
$res=mysql_query($sql);
$i=1;
while(list($row[$i])=mysql_fetch_row($res)) $i++;
上面的語句執(zhí)行之后,$row[1]是第一條數(shù)據(jù),$row[2]是第二條數(shù)據(jù),……下面的語句輸出網(wǎng)頁即可:
echo END
這里放網(wǎng)頁的內(nèi)容,{$row[1]}
直接按照html的語法進行書寫,{$row[2]}
把你各個{$row[3]}數(shù)值的位置用PHP數(shù)組引用即可。
END;
?php
//設(shè)置連接
$DBserver
=
"localhost";
$DBname
=
"數(shù)據(jù)庫";
$DBuser
=
"賬號";
$DBpassword
=
"密碼";
$con
=
mysql_connect("localhost","賬號","密碼");
mysql_select_db("數(shù)據(jù)庫");
$contents
=
file_get_contents($url);
//$contents就是網(wǎng)頁內(nèi)容,$url就是鏈接
$contents
=
mysql_real_escape_string($contents);
//轉(zhuǎn)義,不用可以不要
$SQL="
INSERT
INTO
數(shù)據(jù)庫表(數(shù)據(jù)字段)
VALUES('{$contents}')";
mysql_query($SQL)
or
die(mysql_error());
?
?php
$link=mysql_connect('localhost','用戶名','密碼')or?die("數(shù)據(jù)庫連接失敗");//連接數(shù)據(jù)庫
mysql_select_db('數(shù)據(jù)庫名',$link);//選擇數(shù)據(jù)庫
mysql_query("set?names?utf8");//設(shè)置編碼格式
$q="select?*?from?"數(shù)據(jù)表";//設(shè)置查詢指令
$result=mysql_query($q);//執(zhí)行查詢
while($row=mysql_fetch_assoc($result))//將result結(jié)果集中查詢結(jié)果取出一條
{?echo??返回到HTML;?}
?
html界面使用ajax的成功返回值,再渲染在界面里就行了
可以用以下4個方法來抓取網(wǎng)站 的數(shù)據(jù):
1. 用 file_get_contents 以 get 方式獲取內(nèi)容:
?
$url = '';
$html = file_get_contents($url);
echo $html;
2. 用fopen打開url,以get方式獲取內(nèi)容
?
$url = '';
$fp = fopen($url, 'r');
stream_get_meta_data($fp);
$result = '';
while(!feof($fp))
{
$result .= fgets($fp, 1024);
}
echo "url body: $result";
fclose($fp);
3. 用file_get_contents函數(shù),以post方式獲取url
?
$data = array(
'foo'='bar',
'baz'='boom',
'site'='',
'name'='nowa magic');
$data = http_build_query($data);
//$postdata = http_build_query($data);
$options = array(
'http' = array(
'method' = 'POST',
'header' = 'Content-type:application/x-www-form-urlencoded',
'content' = $data
//'timeout' = 60 * 60 // 超時時間(單位:s)
)
);
$url = "";
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;
4、使用curl庫,使用curl庫之前,可能需要查看一下php.ini是否已經(jīng)打開了curl擴展
$url = '';
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
echo $file_contents;
用PHP自帶函數(shù)就可以實現(xiàn),首先要過去對方的網(wǎng)頁信息,用
file_get_contents();參數(shù)是對方的URL地址,這個函數(shù)返回是一個字符串你想要的東西就在這個字符串中了
接下來就可以針對這個字符串做處理了,說下思路,正如你這個問題想獲取到航班號起飛時間,在這個網(wǎng)頁中應(yīng)該有很多相同的標簽元素,它們都有共同點,用
用正則表達式preg_match();或者是
preg_match_all();這兩個函數(shù)它們都返回一個數(shù)組,這個數(shù)組存的就是你要的航班號和起飛時間,那么相同信息的數(shù)組就會出現(xiàn)了,然后在對這個數(shù)組進行分析找到你要的某個值或全部的值
獲取信息要用到的3個函數(shù)是:
file_get_contents();
preg_match();
preg_match_all();
分享文章:php爬取網(wǎng)頁表格數(shù)據(jù)庫,爬蟲爬取網(wǎng)頁表格數(shù)據(jù)
路徑分享:http://chinadenli.net/article23/dsgiics.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、網(wǎng)站內(nèi)鏈、網(wǎng)站排名、品牌網(wǎng)站制作、App設(shè)計、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)