python抓取网页内容

#-------PYTHON获取网页内容-------------#

import sys, urllib

url = "http://www.163.com" #网页地址

wp = urllib.urlopen(url) #打开连接

content = wp.read() #获取页面内容

fp = open("/home/cx/content.txt","w") #打开一个文本文件

fp.write(content) #写入数据

fp.close() #关闭文件
 
posted on 2012-09-10 20:45  mingaixin  阅读(1178)  评论(0编辑  收藏  举报