Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Scrapy Project in Visual Studio Code

Tags:

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

like image 646
naqushab Avatar asked Mar 09 '18 20:03

naqushab


People also ask

How do I debug a scrapy 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.

How do you debug a scrapy spider?

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.

How do I enable debugging in Visual Studio code?

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.

How do I debug a Python file in Vscode?

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.


1 Answers

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.

like image 70
cpinamtz Avatar answered Sep 19 '22 16:09

cpinamtz