I have Visual Studio Code on a Windows Machine, on which I am making a new Scrapy Crawler. The crawler is working fine but I want to debug the code, for which I am adding this in my launch.json
file:
{ "name": "Scrapy with Integrated Terminal/Console", "type": "python", "request": "launch", "stopOnEntry": true, "pythonPath": "${config:python.pythonPath}", "program": "C:/Users/neo/.virtualenvs/Gers-Crawler-77pVkqzP/Scripts/scrapy.exe", "cwd": "${workspaceRoot}", "args": [ "crawl", "amazon", "-o", "amazon.json" ], "console": "integratedTerminal", "env": {}, "envFile": "${workspaceRoot}/.env", "debugOptions": [ "RedirectOutput" ] }
But I am unable to hit any breakpoints. PS: I took the JSON script from here: http://www.stevetrefethen.com/blog/debugging-a-python-scrapy-project-in-vscode
Set the breakpoints wherever you want and then debug. This should be the accepted answer. Adding a scrapy-specific configuration in the working-project's launch. json is a good practice, easy to implement and doesn't require an additional script to be created.
Start Scrapy Shell from your Spider Code shell. inspect_response method in your spider code. This will open a Scrapy shell session that will let you interact with the current response object. from scrapy.
To run or debug a simple app in VS Code, select Run and Debug on the Debug start view or press F5 and VS Code will try to run your currently active file. However, for most debugging scenarios, creating a launch configuration file is beneficial because it allows you to configure and save debugging setup details.
If you're only interested in debugging a Python script, the simplest way is to select the down-arrow next to the run button on the editor and select Debug Python File in Terminal.
In order to execute the typical scrapy runspider <PYTHON_FILE>
command you must to set the following config into your launch.json
:
{ "version": "0.1.0", "configurations": [ { "name": "Python: Launch Scrapy Spider", "type": "python", "request": "launch", "module": "scrapy", "args": [ "runspider", "${file}" ], "console": "integratedTerminal" } ] }
Set the breakpoints wherever you want and then debug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With