[請益] php抓取網頁

看板PHP作者 (被遺忘的)時間14年前 (2011/08/19 14:08), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
我要怎樣才能模擬使用者抓取到的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
改user_agent ,內容搜尋googlebot,就有一堆了
08/19 14:40, 1F
文章代碼(AID): #1EJVtwB0 (PHP)
文章代碼(AID): #1EJVtwB0 (PHP)