Python爬虫教程-04-response简介

Spider-04-response简介

本小节介绍urlopen的返回对象,和简单调试方法

案例v3

  • 研究request的返回值,输出返回值类型,打印内容
  • geturl:返回请求对象的url
  • info:请求返回对象的meta信息
  • getcode:返回的http code
# py04v3.py

from urllib import request

if __name__ == '__main__':

    url = 'https://jobs.zhaopin.com/CC375882789J00033399409.htm'

    rsp = request.urlopen(url)
    # 按住Ctrl键不送,同时点击urlopen,可以查看文档,有函数的具体参数和使用方法

    print("rsp的类型:{0}".format(type(rsp)))
    print("rsp的内容:{0}".format(rsp))
    print("url为:{0}".format(rsp.geturl()))
    print("Info为:{0}".format(rsp.info()))
    print("Code为:{0}".format(rsp.getcode()))


    html = rsp.read()

右键运行,截图如下

《Python爬虫教程-04-response简介》
《Python爬虫教程-04-response简介》

关于调试

  • 在代码左侧【行号】上单击,出现红点,及断点
  • 右键【Debug ‘项目名’】

《Python爬虫教程-04-response简介》
《Python爬虫教程-04-response简介》

控制台截图如下
包括请求过程中的参数

《Python爬虫教程-04-response简介》
《Python爬虫教程-04-response简介》

urlopen的返回对象,和简单调试方法就介绍到这里了

原文:

https://blog.csdn.net/qq_40147863/article/details/81460484blog.csdn.net

    原文作者:NicePython
    原文地址: https://zhuanlan.zhihu.com/p/62247150
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞