代碼如下:?View Code PHP include("conn.php");//調用數據庫連接文件 echo "table width=572 height=56 border=0 cellspacing=1 "; //創建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循環mysql_fetch_array()并將數據返回數組 echo "tr onmouseout=this.style.backgroundColor='' onMouseOver=this.style.backgroundColor='#99CC33' bgcolor=#CCCCCC"; echo "td$row[0]/td"; //輸出數組中數據 echo "td$row[1]/td"; echo "td$row[2]/td"; echo "td$row[3]/td"; echo "td$row[4]/td"; echo "/tr"; } echo "/table";輸出記錄截圖
創新互聯公司專業為企業提供坡頭網站建設、坡頭做網站、坡頭網站設計、坡頭網站制作等企業網站建設、網頁設計與制作、坡頭企業網站模板建站服務,10年坡頭做網站經驗,不只是建網站,更提供有價值的思路和整體網絡服務。
可以用以下4個方法來抓取網站 的數據:
1. 用 file_get_contents 以 get 方式獲取內容:
?
$url = '';
$html = file_get_contents($url);
echo $html;
2. 用fopen打開url,以get方式獲取內容
?
$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函數,以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是否已經打開了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;
認要顯示15條數據,因此,我們先從數據庫取開始的15條數據顯示在頁面。后面新加載的數據,我們也按每次15條的方式展示。
為了講解盡量簡單,我使用原生的PHP和mysql查詢語句。首先,需要連接數據庫,包含連接信息的connnect.php。這里我定義了幾個用戶id。
然后查詢數據表,獲得結果集,并循環輸出,代碼如下:
php
require_once('connect.php');
$user = array('demo1','demo2','demo3','demo3','demo4');
$amp;amp;$nbsp;
div id="container"$amp;amp;$nbsp;
php
用PHP自帶函數就可以實現,首先要過去對方的網頁信息,用
file_get_contents();參數是對方的URL地址,這個函數返回是一個字符串你想要的東西就在這個字符串中了
接下來就可以針對這個字符串做處理了,說下思路,正如你這個問題想獲取到航班號起飛時間,在這個網頁中應該有很多相同的標簽元素,它們都有共同點,用
用正則表達式preg_match();或者是
preg_match_all();這兩個函數它們都返回一個數組,這個數組存的就是你要的航班號和起飛時間,那么相同信息的數組就會出現了,然后在對這個數組進行分析找到你要的某個值或全部的值
獲取信息要用到的3個函數是:
file_get_contents();
preg_match();
preg_match_all();
獲取ppq數據庫的所有表名的代碼:
?php
$server='localhost';
$user='root';
$pass='12345';
$dbname='ppq';
$conn=mysql_connect($server,$user,$pass);
if(!$conn)
die("數據庫系統連接失敗!");
$result=mysql_list_tables($dbname);
if(!$result)
die("數據庫連接失敗!");
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
數據庫中的表
說明
resource
mysql_list_tables
(
string
database
[,
resource
link_identifier])
mysql_list_tables()
接受一個數據庫名并返回和
mysql_query()
函數很相似的一個結果指針。用
mysql_fetch_array()或者用mysql_fetch_row()來獲得一個數組,數組的第0列就是數組名,當獲取不到時
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE。
當前標題:php抓取網站商城數據庫 php獲取網頁
路徑分享:http://m.kartarina.com/article28/hgjpjp.html
成都網站建設公司_創新互聯,為您提供網站建設、品牌網站制作、外貿網站建設、面包屑導航、用戶體驗、全網營銷推廣
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯