作者MacMini (被遗忘的)
看板PHP
标题[请益] php抓取网页
时间Fri Aug 19 14:08:55 2011
我要怎样才能模拟使用者抓取到的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)
1F:→ arrack:改user_agent ,内容搜寻googlebot,就有一堆了 08/19 14:40