Re: [請益] 請問一下要怎麼用php抓網頁原始檔裡的렠…
※ 引述《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: 163.16.1.95
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章