代碼如下:?View Code PHP include("conn.php");//調(diào)用數(shù)據(jù)庫連接文件 echo "table width=572 height=56 border=0 cellspacing=1 "; //創(chuàng)建html表格 echo "tr bgcolor=#9999FF"; echo "th width=33 scope=colid/th"; echo "th width=100 scope=coluser_name/th "; echo "th width=100 scope=coluser_pass/th "; echo "th width=100 scope=colstaus/th"; echo "th width=100 scope=colinsert_time/th"; echo "/tr"; $SQL = "select * from user_info"; $query = mysql_query($SQL); //SQL查詢語句 while ($row = mysql_fetch_array($query)){ //使用while循環(huán)mysql_fetch_array()并將數(shù)據(jù)返回?cái)?shù)組 echo "tr onmouseout=this.style.backgroundColor='' onMouseOver=this.style.backgroundColor='#99CC33' bgcolor=#CCCCCC"; echo "td$row[0]/td"; //輸出數(shù)組中數(shù)據(jù) echo "td$row[1]/td"; echo "td$row[2]/td"; echo "td$row[3]/td"; echo "td$row[4]/td"; echo "/tr"; } echo "/table";輸出記錄截圖

創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供坡頭網(wǎng)站建設(shè)、坡頭做網(wǎng)站、坡頭網(wǎng)站設(shè)計(jì)、坡頭網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、坡頭企業(yè)網(wǎng)站模板建站服務(wù),10年坡頭做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
可以用以下4個(gè)方法來抓取網(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 // 超時(shí)時(shí)間(單位:s)
)
);
$url = "";
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;
4、使用curl庫,使用curl庫之前,可能需要查看一下php.ini是否已經(jīng)打開了curl擴(kuò)展
$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;
認(rèn)要顯示15條數(shù)據(jù),因此,我們先從數(shù)據(jù)庫取開始的15條數(shù)據(jù)顯示在頁面。后面新加載的數(shù)據(jù),我們也按每次15條的方式展示。
為了講解盡量簡單,我使用原生的PHP和mysql查詢語句。首先,需要連接數(shù)據(jù)庫,包含連接信息的connnect.php。這里我定義了幾個(gè)用戶id。
然后查詢數(shù)據(jù)表,獲得結(jié)果集,并循環(huán)輸出,代碼如下:
php
require_once('connect.php');
$user = array('demo1','demo2','demo3','demo3','demo4');
$amp;amp;$nbsp;
div id="container"$amp;amp;$nbsp;
php
用PHP自帶函數(shù)就可以實(shí)現(xiàn),首先要過去對(duì)方的網(wǎng)頁信息,用
file_get_contents();參數(shù)是對(duì)方的URL地址,這個(gè)函數(shù)返回是一個(gè)字符串你想要的東西就在這個(gè)字符串中了
接下來就可以針對(duì)這個(gè)字符串做處理了,說下思路,正如你這個(gè)問題想獲取到航班號(hào)起飛時(shí)間,在這個(gè)網(wǎng)頁中應(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();
獲取ppq數(shù)據(jù)庫的所有表名的代碼:
?php
$server='localhost';
$user='root';
$pass='12345';
$dbname='ppq';
$conn=mysql_connect($server,$user,$pass);
if(!$conn)
die("數(shù)據(jù)庫系統(tǒng)連接失敗!");
$result=mysql_list_tables($dbname);
if(!$result)
die("數(shù)據(jù)庫連接失敗!");
while($row=mysql_fetch_row($result))
{
echo
$row[0]."
";
}
mysql_free_result($result);
?
mysql_list_tables
(PHP
3,
PHP
4
,
PHP
5)
mysql_list_tables
--
列出
MySQL
數(shù)據(jù)庫中的表
說明
resource
mysql_list_tables
(
string
database
[,
resource
link_identifier])
mysql_list_tables()
接受一個(gè)數(shù)據(jù)庫名并返回和
mysql_query()
函數(shù)很相似的一個(gè)結(jié)果指針。用
mysql_fetch_array()或者用mysql_fetch_row()來獲得一個(gè)數(shù)組,數(shù)組的第0列就是數(shù)組名,當(dāng)獲取不到時(shí)
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE。
當(dāng)前標(biāo)題:php抓取網(wǎng)站商城數(shù)據(jù)庫 php獲取網(wǎng)頁
路徑分享:http://chinadenli.net/article28/hgjpjp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、品牌網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、面包屑導(dǎo)航、用戶體驗(yàn)、全網(wǎng)營銷推廣
聲明:本網(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)