zoukankan      html  css  js  c++  java
  • 爬虫第六节 Debugelog实战

    # DebugeLog
    # 1.首先,我们先先来了解一下DebugLog是什么?
    # 我们经常说的BUG就是错误,Debug就是调试错误,LOG代表日志,
    # 所以,,,DebugLog就是调试日志,这个可以帮助我们在运行程序的过程中打印日志,接下来,我们就开始开启DebugLog:
    #1 )分别使用 urllib.request.HTTPHandler()和 urllib.request.HTTPSHandler()将 debuglevel 设置为1。
    # 2)使用urllib.request.build_opener()创建自定义的opener对象,并使用 1) 中设置的值 作为参数。
    # 3 )用urllib.request.install_opener()创建全局默认的opener对象,这样,在使用 urlopen()时,也会使用我们安装的opener对象。
    # 4)进行后续相应的操作,比如urlopen()等。
    # 此时,根据以上思路,我们可以通过如下代码开启DebugLog:
    import urllib.request

    httphd = urllib.request.HTTPHandler(debuglevel=1)
    httpshd = urllib.request.HTTPSHandler(debuglevel=1)
    opener = urllib.request.build_opener(httphd, httpshd)
    urllib.request.install_opener(opener)
    data = urllib.request.urlopen("http://www.baidu.com")
    print(data)

    #通过运行可以看出 此时会边执行程序,边打印调试的Log日志,成功开启DebugLog
    # 运行结果
    # send: b'GET / HTTP/1.1 Accept-Encoding: identity Host: www.baidu.com User-Agent: Python-urllib/3.7 Connection: close '
    # reply: 'HTTP/1.1 200 OK '
    # header: Bdpagetype: 1
    # header: Bdqid: 0x9449a1a000371840
    # header: Cache-Control: private
    # header: Content-Type: text/html;charset=utf-8
    # header: Date: Mon, 11 May 2020 14:22:19 GMT
    # header: Expires: Mon, 11 May 2020 14:22:10 GMT
    # header: P3p: CP=" OTI DSP COR IVA OUR IND COM "
    # header: P3p: CP=" OTI DSP COR IVA OUR IND COM "
    # header: Server: BWS/1.1
    # header: Set-Cookie: BAIDUID=E14DF6729EC225F410B5ABF5C200AA91:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
    # header: Set-Cookie: BIDUPSID=E14DF6729EC225F410B5ABF5C200AA91; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
    # header: Set-Cookie: PSTM=1589206939; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
    # header: Set-Cookie: BAIDUID=E14DF6729EC225F4E6B41365E6A49293:FG=1; max-age=31536000; expires=Tue, 11-May-21 14:22:19 GMT; domain=.baidu.com; path=/; version=1; comment=bd
    # header: Set-Cookie: BDSVRTM=0; path=/
    # header: Set-Cookie: BD_HOME=1; path=/
    # header: Set-Cookie: H_PS_PSSID=1435_31326_21114_31592_31270_31464_31322_30824_31163; path=/; domain=.baidu.com
    # header: Traceid: 1589206939239644749810685249299483662400
    # header: Vary: Accept-Encoding
    # header: Vary: Accept-Encoding
    # header: X-Ua-Compatible: IE=Edge,chrome=1
    # header: Connection: close
    # header: Transfer-Encoding: chunked
    # <http.client.HTTPResponse object at 0x00000299A143E988> #这才是爬到的结果 上面的只是调试日志
    #
    # Process finished with exit code 0
  • 相关阅读:
    Java操作excel,读取及导出
    vue 在package.json配置对外暴露访问地址(手机端访问本地项目地址)
    element UI upload组件上传附件格式限制
    linux之vim/vi快速复制多行内容的快捷键
    使用vant的Toast组件时提示not defined
    如何使用js判断当前页面是pc还是移动端打开的
    JavaScript 保留两位小数函数
    Linux其他命令
    linux学习ls的三个选项 lha的作用和隐藏文件的知识
    vue+ element-ui el-table组件自定义合计(summary-method)坑
  • 原文地址:https://www.cnblogs.com/kwkk978113/p/12872726.html
Copyright © 2011-2022 走看看