实现在网上爬取网页内容
#!/usr/bin/env python
# encoding: utf-8
import urllib2
# 定义一个要爬取的网页
url = 'http://www.example.com/'
# 打开这个网页,读取其内容
request = urllib2.Request(url)
response = urllib2.urlopen(request)
data = response.read()
# 将内容写入到文件中
with open('example.html','w') as f:
f.write(data)