scrapy shell 默认使用python 控制台,用起来还挺麻烦的,于是想用ipython进行替换,官网给出了两种方式
配置方式
1. 全局设置
通过配置环境变量的方式,添加SCRAPY_PYTHON_SHELL
为ipython
2.局部设置
只在当前scrapy项目下使用ipython,需要修改scrapy.cfg配置文件,setting下添加一行
[settings]
shell = bpython
cd 到当前scrapy项目下即可使用ipython的shell
tab 补全时的debug提示干扰解决
使用ipython后会有以下情况,当使用tab进行补全时会出现干扰的debug信息
In [2]: res2022-06-29 10:36:57.804 | DEBUG | parso.python.diff:update:282 - diff parser start
2022-06-29 10:36:57.806 | DEBUG | parso.python.diff:update:293 - line_lengths old: 1; new: 1
2022-06-29 10:36:57.807 | DEBUG | parso.python.diff:update:296 - -> code[replace] old[1:1] new[1:1]
2022-06-29 10:36:57.809 | DEBUG | parso.python.diff:_parse:421 - parse_part from 1 to 1 (to 0 in part parser)
2022-06-29 10:36:57.810 | DEBUG | parso.python.diff:update:339 - diff parser end
1.全局设置
1.1 F**K parso
pip uninstall parso
1.2 修改parso模块的debug设置
搜索当前python环境 Python38\Lib\site-packages\parso\python\diff.py
from parso.python.tokenize import PythonToken, BOM_UTF8_STRING
from parso.python.token import PythonTokenTypes
LOG = logging.getLogger(__name__)
DEBUG_DIFF_PARSER = False
# 以下为自行添加
logging.getLogger('parso.python.diff').disabled = True
logging.getLogger("parso.cache").disabled = True
2 shell启动配置
1. 提高日志级别,规避debug log
scrapy shell -L INFO https://example.com
2. shell中单独关闭对应的日志
__import__("logging").getLogger("parso.python.diff").disabled=True