[請益] 利用php讀取URL網頁

看板PHP作者 (梅)時間14年前 (2011/05/20 13:23), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
我知道用fopen來讀取網頁 我試著去取得yahoo的網址的內容,可以成功 但是換成google卻不行 以下是原始碼: <?php header("Content-Type: text/html; charset=utf-8"); $s="花生醬"; $encode_url = urlencode($s); //$url = "http://tw.search.yahoo.com/search?p=".$encode_url.'&fr=yfp&ei=utf-8&v=0'; //http://tw.search.yahoo.com/search?p=%E8%8D%89%E6%B3%A5%E9%A6%AC&fr=yfp&ei=utf-8&v=0 //echo '<pre>'.htmlspecialchars($str).'</pre>'; $url = "http://www.google.com.tw/search?q=".$encode_url; //http://www.google.com.tw/search?q=%E8%8A%B1%E7%94%9F%E9%86%AC $str = file_get_contents($url); echo '<pre>'.htmlspecialchars($str).'</pre>'; ?> 花生醬是我想要查詢的關鍵字,我有把它經過編碼了。 想請問各位大大 為什麼在yahoo可以,在google卻不行呢? 不過直接將網址貼到瀏覽器上是可以執行的 但是執行這個php會出現Error 403 (Forbidden)!! 謝謝大大謝謝大大 幫幫忙唷~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.25.118.153

05/22 03:15, , 1F
試試cURL,user-agent的設定注意一下
05/22 03:15, 1F
文章代碼(AID): #1DrVh6YJ (PHP)
文章代碼(AID): #1DrVh6YJ (PHP)