Re: [請益] 請問一下要怎麼用php抓網頁原始檔裡的렠…

看板PHP作者 (翰)時間18年前 (2006/05/22 12:53), 編輯推噓5(501)
留言6則, 5人參與, 最新討論串2/2 (看更多)
不好意思 我的都會出現: Fatal error: Call to undefined function: curl_init() in c:\appserv\www\051803.php on line 5 是因為php版本不同 才會沒有curl_init() 這個function嗎 謝謝 ※ 引述《wawawa (哇哇哇○( ̄﹏ ̄)○)》之銘言: : ※ 引述《destroit (翰)》之銘言: : : 各位大大 請問一下 : : 要怎麼用php抓網頁原始檔裡的資料 : : 謝謝 : 以下是簡單範例,詳細用法去看官網curl相關用法 : <?php : //抓網頁 : $url = "http://tw.dictionary.yahoo.com/search?ei=UTF-8&p=".$_POST['words']; : //雅虎的查詢網址 : $ch = curl_init(); //初始化curl,要準備開始抓網頁 : curl_setopt($ch, CURLOPT_URL, $url); //告訴url要抓的是第一行的網頁 : curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //不要將抓回來的網頁秀到螢幕上, : //等等我們要繼續分析 : $content = curl_exec($ch); //抓吧,然後將資料存到$content : //開始分析,以下是用正規表示式 : preg_match('/<div class=pexplain>(.+?)<\/div>/', $content, $target); //將抓到 : //的字串存到$target : echo $target[1]; //印到螢幕上 : ?> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.120.46.5

05/22 13:00, , 1F
curl_init (PHP 4 >= 4.0.2, PHP 5)
05/22 13:00, 1F

05/22 13:41, , 2F
而且好像還要有什麼設定才能用的樣子...
05/22 13:41, 2F

05/22 14:24, , 3F
要將curl模組裝進去...不行的話只好用fopen自己刻囉
05/22 14:24, 3F

05/22 16:14, , 4F
拿掉php.ini中 ;extension=php_curl.dll前面的分號
05/22 16:14, 4F

05/22 16:14, , 5F
存檔後重新啟動伺服器就可以了
05/22 16:14, 5F

05/22 22:49, , 6F
抓原始檔用file_contents不是就可以了嗎?
05/22 22:49, 6F
文章代碼(AID): #14SKEtEh (PHP)
文章代碼(AID): #14SKEtEh (PHP)