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