如何使用 PyCharm 调试 Scrapy 项目 [英] How to use PyCharm to debug Scrapy projects

查看:27
本文介绍了如何使用 PyCharm 调试 Scrapy 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Python 2.7 开发 Scrapy 0.20.我发现 PyCharm 有一个很好的 Python 调试器.我想用它来测试我的 Scrapy 蜘蛛.请问有人知道怎么做吗?

I am working on Scrapy 0.20 with Python 2.7. I found PyCharm has a good Python debugger. I want to test my Scrapy spiders using it. Anyone knows how to do that please?

File->Setting->Project structure->Add content root.

但我不知道我还能做什么

But I don't know what else I have to do

推荐答案

scrapy 命令是一个 Python 脚本,这意味着您可以从 PyCharm 内部启动它.

The scrapy command is a python script which means you can start it from inside PyCharm.

当你检查scrapy二进制文件(which scrapy)时,你会注意到这实际上是一个python脚本:

When you examine the scrapy binary (which scrapy) you will notice that this is actually a python script:

#!/usr/bin/python

from scrapy.cmdline import execute
execute()

这意味着像这样的命令scrapy crawl IcecatCrawler 也可以这样执行: python/Library/Python/2.7/site-packages/scrapy/cmdline.py crawl IcecatCrawler

This means that a command like scrapy crawl IcecatCrawler can also be executed like this: python /Library/Python/2.7/site-packages/scrapy/cmdline.py crawl IcecatCrawler

尝试找到scrapy.cmdline 包.就我而言,位置在这里:/Library/Python/2.7/site-packages/scrapy/cmdline.py

Try to find the scrapy.cmdline package. In my case the location was here: /Library/Python/2.7/site-packages/scrapy/cmdline.py

使用该脚本作为脚本在 PyCharm 中创建运行/调试配置.用scrapy 命令和spider 填充脚本参数.在这种情况下 crawl IcecatCrawler.

Create a run/debug configuration inside PyCharm with that script as script. Fill the script parameters with the scrapy command and spider. In this case crawl IcecatCrawler.

像这样:

将断点放在爬行代码中的任何位置,它应该可以工作™.

Put your breakpoints anywhere in your crawling code and it should work™.

这篇关于如何使用 PyCharm 调试 Scrapy 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆