Python爬取google搜索结果

使用Python爬取google的搜索结果:

   1: # -*- coding: utf-8 -*-
   2: import urllib2
   3: import cookielib
   4:  
   5: url = 'http://www.google.com.hk/search?sourceid=chrome&;ie=UTF-8&q=python'
   6: cj = cookielib.CookieJar()
   7: opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) 
   8: opener.addheaders = [('User-agent', 'Opera/9.23')] 
   9: urllib2.install_opener(opener) 
  10: req=urllib2.Request(url) 
  11: response =urllib2.urlopen(req)
  12: content = response.read()
  13: print content

参见:http://blog.csdn.net/wyingquan/article/details/3404112

posted @ 2012-07-26 12:28  MindMac  阅读(890)  评论(0编辑  收藏  举报