[請益] php抓取網頁
我要怎樣才能模擬使用者抓取到的google網頁?
目前寫法
function get_page($url) {
$user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;
Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec($ch);
curl_close($ch);
return $html;
}
可是我發現這樣抓的話每次所顯示出來的網頁會有所不同
(大致上會有兩個版本)
我要怎麼做才能做到我抓的google網頁跟
用瀏覽器開google看到的網頁一致呢?
還有 curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
這段主要是用來做什麼的呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.32.228.158
※ 編輯: MacMini 來自: 114.32.228.158 (08/19 14:09)
※ 編輯: MacMini 來自: 114.32.228.158 (08/19 14:10)
→
08/19 14:40, , 1F
08/19 14:40, 1F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章
151
156