python 简单爬虫一

import urllib.request

#网址  
url = "http://www.douban.com/"  

#请求  
request = urllib.request.Request(url)  

#爬取结果  
response = urllib.request.urlopen(request)  

data = response.read()  

#设置解码方式  
data = data.decode('utf-8')  

#打印结果  
print(data)  

#打印爬取网页的各类信息  

print(type(response))
print(response.geturl())
print(response.info())
print(response.getcode()) 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章