1、知识点

"""
logging :
scrapy:
settings中设置LOG_LEVEL="WARNING"
settings中设置LOG_FILE="./log.log" #设置日志保存的位置,设置后在终端不会显示日志内容
import logging 实例化一个logger的方式在任何文件中使用logger输出内容
logger = logging.getLogger(__name__) #实例化
普通项目中:
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
filename='myapp.log',
filemode='w') #设置日志输出格式
实例化一个ogger = logging.getLogger(__name__)
在任何py文件中调用logger即可
"""

2、scrapy项目中使用logging

# -*- coding: utf-8 -*-
import scrapy
import logging logger = logging.getLogger(__name__)
class JulyeduSpider(scrapy.Spider):
name = 'julyedu'
allowed_domains = ['julyedu.com']
start_urls = ['http://julyedu.com/']
#这个parse方法名不能改
def parse(self, response):
"""
爬虫七月在线的导师名单
:param response:
:return:
"""
list_li = response.xpath("//div[@class='swiper-wrapper']//li")
#print(list_li)
item = {}
for li in list_li:
item["name"] = li.xpath(".//h3/text()").extract_first()
item["content"] = li.xpath(".//p[@class='teacherBrief']/text()").extract_first()
#item["content"] = li.xpath(".//p[@class='teacherIntroduction']/text()").extract_first()
#print(item)
#将数据传递道pipelines,yield只接受Request,BaseItem,dict,None四种类型
logger.warning(item) #打印日志
yield item

2、普通项目中

  a)建立一个通用的log_a.py

# coding = utf-8
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
filename='myapp.log',
filemode='w') logger = logging.getLogger(__name__) if __name__ == '__main__':
logger.info("this is a log ")

  b)log_b.py文件使用通用的log_a.py

# coding = utf-8
from log_a import logger if __name__ == '__main__':
logger.warning("b文件")

python之scrapy模块logging日志的更多相关文章

  1. python 自动化之路 logging日志模块

    logging 日志模块 http://python.usyiyi.cn/python_278/library/logging.html 中文官方http://blog.csdn.net/zyz511 ...

  2. python 项目实战之logging日志打印

    官网介绍:https://docs.python.org/2/library/logging.html 一. 基础使用 1.1 logging使用场景 日志是什么?这个不用多解释.百分之九十的程序都需 ...

  3. python之scrapy模块pipelines

    1.知识点 """" pipelines使用: 1.在spiders里面使用yield生成器 list_li = response.xpath("// ...

  4. python基础语法13 内置模块 subprocess,re模块,logging日志记录模块,防止导入模块时自动执行测试功能,包的理论

    subprocess模块: - 可以通过python代码给操作系统终端发送命令, 并且可以返回结果. sub: 子    process: 进程 import subprocess while Tru ...

  5. 【python接口自动化】- logging日志模块

    前言:我们之前运行代码时都是将日志直接输出到控制台,而实际项目中常常需要把日志存储到文件,便于查阅,如运行时间.描述信息以及错误或者异常发生时候的特定上下文信息. logging模块介绍 ​ Pyth ...

  6. python 安装 Scrapy 模块

    环境的安装总是让人多愁善感,爱恨交叉... 本人安装环境:win7 64 + python2.7 先来几个网站 https://doc.scrapy.org/en/latest/intro/insta ...

  7. python之scrapy模块scrapy-redis使用

    1.redis的使用,自己可以多学习下,个人也是在学习 https://www.cnblogs.com/ywjfx/p/10262662.html官网可以自己搜索下. 2.下载安装scrapy-red ...

  8. python之scrapy模块下载中间件

    知识点 使用方法: 编写一个Downloader Middlewares和我们编写一个pipeline一样,定义一个类,然后在setting中开启 Downloader Middlewares默认的方 ...

  9. python包-logging-hashlib-openpyxl模块-深浅拷贝-04

    包 包: # 包是一系列模块文件的结合体,表现形式是文件夹,该文件夹内部通常会包含一个__init__.py文件,本质上还是一个模块 包呢,就是前两篇博客中提到的,模块的四种表现形式中的第三种 # 把 ...

随机推荐

  1. 微信小程序开发(十一)获取手机的完整详细信息

    // succ.wxml <view style='position:absolute; top:30%; left:35%;font-size:36rpx'>{{name}}:签到成功. ...

  2. E - GCD HDU - 2588

    The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the ...

  3. okhttp拦截器之CacheInterceptor解析

    在上一次[https://www.cnblogs.com/webor2006/p/9150658.html]了解了缓存的存与取的细节之后,接下来就可以分析一下OkHttp的缓存拦截器啦: OkHttp ...

  4. c语言啊

    双链表 quacklist 内核  模块加载

  5. table 随着内容自动适应宽度

    td { white-space: nowrap; } 给td加个属性就可以了,如果有th则可以 td,th 本文来自:https://blog.csdn.net/liuhongwei_study/a ...

  6. DAG及拓扑排序

    1.有向无环图和拓扑排序 有向无环图(Directed Acyclic Graph,简称DAG):拓扑排序指的对DAG一个有序的线性排列.即每次选出一个没有入度的节点,然后输出该点并将节点和其相关连的 ...

  7. luogu3651 展翅翱翔之时 (はばたきのとき)[基环树+贪心]

    考前随便做点水题愉♂悦身心 有助于退役 这题意思其实就是说要把外向基环树森林改成一个环的最小代价. 依照套路,先对每棵基环树的树做dp,这里因为要是环,要把所有的树都拆成链,然后连接.所以考虑以最小代 ...

  8. ao的mobile解决方案

    http://aicdg.com/ue4-msaa-depth/ http://aicdg.com/vulkan-mass-shader-resolve/ ao两篇paper 分bake和realti ...

  9. Ubuntu14版桌面突然卡住怎么办

    参考:https://blog.csdn.net/hautxuhaihu/article/details/78924926 (1)ctrl+alt+f1...6进入命令行终端.用户名,密码登录. (2 ...

  10. mysql数据库系统学习(一)---一条SQL查询语句是如何执行的?

    本文基于----MySQL实战45讲(极客时间----林晓斌 )整理----->https://time.geekbang.org/column/article/68319 一.第一节:一条sq ...