Python学习笔记Day
本文用到的是Python 3 如果是 Python 2 请移步到其他博文 谢谢 如果不足 或错误 请大神指点。本人小白
Python3学习网站 https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000 (感谢廖大神的博文)
''''' 第一个示例:简单的网页爬虫 爬取豆瓣首页 ''' 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())
结果
如有不托 请大神指点
参考博文 http://blog.csdn.net/fly_yr/article/details/51525435 (感谢博主)