本文目錄一覽:
- 1、PHP獲取遠程頁面html
- 2、php怎麼抓取 淘寶搜索頁面的Html內容
- 3、php新手在線等答案:用php如何讓提取html表單中輸入的數據???
- 4、php讀取html
- 5、php正則表達來獲取html中的部分內容
- 6、php定時抓html內容和保存讀取
PHP獲取遠程頁面html
file_get_contents()比file()慢?
如果抓取別人的頁面還是用file_get_contents()比較好~
file()取回的是數組
而file_get_contents()取回的是字元串
你是想取回個數組再把它們連起來方便?還是直接把他們取回來方便?
另外
file_get_contents(String,int)
有個可選參數設定讀取的長度
在PHP手冊中說:
file_get_contents() 函數是用來將文件的內容讀入到一個字元串中的首選方法。如果操作系統支持還會使用內存映射技術來增強性能。
php怎麼抓取 淘寶搜索頁面的Html內容
發送http頭信息試試,另外想要做蜘蛛程序的話,還是python比較好用,有豐富了web類庫
php新手在線等答案:用php如何讓提取html表單中輸入的數據???
在form中,的屬性method=get
或者post方法,
在php中獲取表單數據如下:
$_get[表單名]
$_post[表單名]
這樣就可以獲取到html中表單裡面的數據信息
php讀取html
preg_match(‘/p align=\”center\”bigstrong(.*?)\/strong\/big\/p/’,$str,$result);
$str就是上面的html裡面的內容,$result就是匹配到的字元串,你可以print_r($result);看看裡面就有你要的結果,或者直接echo $result[1];就是
「在LINUX下配置MYSQL、PHP和JSP」這幾個字元了
請採納。
php正則表達來獲取html中的部分內容
1、幾種函數的簡單說明:
(1)preg_grep — 返回與模式匹配的數組單元
preg_grep 返回一個input 數組中與給定的 pattern 模式相匹配的單元所組成的數組。
(2)preg_match — 進行正則表達式匹配
說明:int preg_match ( string pattern, string subject [, array matches [, int flags]] )在 subject 字元串中搜索與 pattern 給出的正則表達式相匹配的內容。 返回值0或1。
(3)preg_replace — 執行正則表達式的搜索和替換
(4)preg_split — 用正則表達式分割字元串
2. 一般來說,如果用正則來獲取匹配內容,一般使用 preg_match/ preg_match_all 函數。
補充回答:
正則表達式如下:
‘%div class=”wap2″span功能/span(.*?)/div%si’
以下是代碼,經測試,運行正常:
?php
$str = ‘div class=”wap2″span功能/span這裡面是要獲取的內容,不能確定什麼字元,可能是數字(123456…)字母(babaidn…),特殊浮等(o_O\(^o^)/…)/div’;
$pa = ‘%div class=”wap2″span功能/span(.*?)/div%si’;
preg_match($pa,$str,$r);
echo $r[1];
?
php定時抓html內容和保存讀取
?php
@header ( ‘Content-type: text/html;charset=UTF-8’ );
$name = “AA”;
$seconds = 60;
$url = “./”;
$html = $url . $name . “.html”;
$file = $name . “.dat”;
set_time_limit ( 0 );
while ( file_exists ( $file ) ) {
$info = file_get_contents ( $html );
$info = iconv ( “UTF-8”, “GBK”, $info );
echo $info;
if (preg_match ( “/!–開始–((?:(?!!–結束–)[\s\S])*)!–結束–/”, $info, $m )) {
$fh = fopen ( $file, “w” );
fwrite ( $fh, $m [1] );
fclose ( $fh );
}
sleep ( $seconds );
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/187936.html