Re: [問題] 抓 google 網頁的搜尋回傳結果

看板Python作者 (plom)時間17年前 (2007/12/15 22:44), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/6 (看更多)
※ 引述《plom (plom)》之銘言: : ※ 引述《StubbornLin (Victor)》之銘言: : : 嗯~ 經過剛才討論一下 : : 還有我的實驗 : : 發現問題出在Google疑似會擋urllib的User-Agent header : : 以上 : 那請問有人知道如何改寫嗎?只有 python 不能抓, 實在太不公平了 >< 剛又試了一下 import httplib httplib.HTTPConnection.debuglevel = 1 import urllib2 opener = urllib2.build_opener() opener.addheaders = [('User-agent', 'Mozilla/5.0')] opener.open('http://www.google.com.tw/search?q=time&start=20&complete=1&hl=zh-TW&sa=N&btnG=%E6%90%9C%E5%B0%8B').read() send: 'GET /search?q=time&start=20&complete=1&hl=zh-TW&sa=N&btnG=%E6%90%9C%E5%B0 send: 'Host: www.google.com.tw\r\n' send: 'User-agent: Mozilla/5.0\r\n' send: '\r\n' reply: 'HTTP/1.0 200 OK\r\n' 接下來要下什麼指令才能抓網頁呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.192.149.53
文章代碼(AID): #17O-XSHu (Python)
討論串 (同標題文章)
文章代碼(AID): #17O-XSHu (Python)