小鸟游的Python爬虫学习笔记——基本库的使用
2018-06-26 21:12
253 查看
在Python学习中经常碰到的问题就是Python版本的问题,现在全面转向Python3的使用和学习。
在Python2中,有urllib和urllib2两个库来实现请求的发送。而在Python3中,统一为urllib。
一、首先利用urlopen()方法,完成最基本的网页get请求获取:
import urllib.request response = urllib.request.urlopen('https://segmentfault.com') print(response.read().decode('utf-8')) print(type(response)) #查看返回的响应类型 print(response.status) #查看响应状态码 print(response.getheaders) #查看响应头信息 print(response.getheader('Server')) #查看响应头中的server值
运行结果:
第一个打印的结果太长省略了图片是后面的四个打印结果
相关文章推荐
- Python爬虫学习--urllib的基本使用笔记
- python2.7爬虫学习笔记(一)---Urllib库的使用
- Python爬虫(入门+进阶)学习笔记 1-8 使用自动化神器Selenium爬取动态网页(案例三:爬取淘宝商品)
- python爬虫学习笔记五:Re库的介绍和使用
- python爬虫学习笔记六:Scrapy爬虫的使用步骤
- Python爬虫(入门+进阶)学习笔记 1-3 使用Requests爬取豆瓣短评
- python爬虫:使用Mongodb数据库存储数据学习笔记
- [Python]网络爬虫学习笔记,爬取东南大学SEU-wlan的流量使用情况
- python3.4学习笔记(十三) 网络爬虫实例代码,使用pyspider抓取多牛投资吧里面的文章信息,抓取政府网新闻内容
- python2.7爬虫学习笔记(一)---Urllib库的使用
- Python爬虫框架Scrapy 学习笔记 5 ------- 使用pipelines过滤敏感词
- python爬虫学习笔记五:Re库的介绍和使用
- Python爬虫(入门+进阶)学习笔记 1-4 使用Xpath解析豆瓣短评
- Python爬虫(入门+进阶)学习笔记 1-5 使用pandas保存豆瓣短评数据
- python爬虫学习笔记——使用requests库编写爬虫(1)
- python学习笔记:time()和datetime()时间模块的基本使用和示例