如何使用PyCharm来调试Scrapy项目 [英] How to use PyCharm to debug Scrapy projects
问题描述
我尝试过的
其实我试着运行蜘蛛一个脚印。结果,我建立了这个脚印。然后,我试图将我的Scrapy项目添加到PyCharm中,作为这样的模型:
文件 - >设置 - >项目结构 - >添加内容根。
但我不知道还有什么我要做的
scrapy
命令是一个python脚本,这意味着您可以从PyCharm内部启动它。
当您检查scrapy二进制(哪些scrapy
)时,您会注意到这实际上是一个python脚本:
#!/ usr / bin / python
from scrapy.cmdline import execute
execute()
这意味着像
scrapy crawl的命令IcecatCrawler
也可以这样执行: python /Library/Python/2.7/site-packages/scrapy/cmdline.py crawl IcecatCrawler
尝试找到scrapy.cmdline包。
在我的情况下,位置在这里: /Library/Python/2.7/site-packages/scrapy/cmdline.py
使用该脚本作为脚本在PyCharm中创建运行/调试配置。使用scrapy命令和蜘蛛填写脚本参数。在这种情况下 crawl IcecatCrawler
。
像这样:
将您的断点放在抓取代码的任何位置,并且应该可以运行。
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?
What I have tried
Actually I tried to run the spider as a scrip. As a result, I built that scrip. Then, I tried to add my Scrapy project to PyCharm as a model like this:
File->Setting->Project structure->Add content root.
But I don't know what else I have to do
The scrapy
command is a python script which means you can start it from inside PyCharm.
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()
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
Try to find the scrapy.cmdline package.
In my case the location was here: /Library/Python/2.7/site-packages/scrapy/cmdline.py
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
.
Like this:
Put your breakpoints anywhere in your crawling code and it should work™.
这篇关于如何使用PyCharm来调试Scrapy项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!