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

看板Python作者 (plom)時間17年前 (2007/12/15 17:47), 編輯推噓1(103)
留言4則, 1人參與, 最新討論串1/6 (看更多)
各位:請教一下,丟關鍵字(dog)到 google 做檢索, 我要回傳的網頁結果做加工再應用,請問各位那邊出錯呢? 或是有人有這方面的範例可參考嗎? #-------------------- # Main Program #-------------------- def main(): import urllib webpac = 'http://www.google.com.tw/search?' searchdic = {} searchdic['q'] = 'dog' searchdic['complete'] = '1' searchdic['hl'] = 'zh-TW' searchdic['start'] = '10' searchdic['sa'] = 'N' searchdic['btnG']='%E6%90%9C%E5%B0%8B' params = urllib.urlencode(searchdic) html = urllib.urlopen(webpac, params) for i in html.readlines():print i if __name__ == '__main__': main() 執行結果: <H1>Not Implemented</H1> The server is unable to process your request. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.192.149.53

12/15 17:49, , 1F
程式的做法看起來沒問題 應該是你的參數給錯
12/15 17:49, 1F

12/15 17:49, , 2F
像btnG這一欄 已經是escape後的形式了
12/15 17:49, 2F

12/15 17:49, , 3F
說錯 encode後 再被encode一次 就變成不是你要的東西
12/15 17:49, 3F

12/15 17:50, , 4F
應該是說 不是btnG編碼前的東西 而是 %E6%...這樣的
12/15 17:50, 4F
文章代碼(AID): #17OwAxLi (Python)
文章代碼(AID): #17OwAxLi (Python)