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?
<I am running scrapy in a virtualenv with Python 3.5.0 and setting the "script" parameter to /path_to_project_env/env/bin/scrapy
solved the issue for me.
You just need to do this.
Create a Python file on crawler folder on your project. I used main.py.
Inside your main.py put this code below.
from scrapy import cmdline
cmdline.execute("scrapy crawl spider".split())
And you need to create a "Run Configuration" to run your main.py.
Doing this, if you put a breakpoint at your code it will stop there.
I use this simple script:
from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings
process = CrawlerProcess(get_project_settings())
process.crawl('your_spider_name')
process.start()
As of 2018.1 this became a lot easier. You can now select Module name
in your project's Run/Debug Configuration
. Set this to scrapy.cmdline
and the Working directory
to the root dir of the scrapy project (the one with settings.py
in it).
Like so:
Now you can add breakpoints to debug your code.