在 Visual Studio Code 中调试 Scrapy 项目 [英] Debugging Scrapy Project in Visual Studio Code

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

问题描述

我在一台 Windows 机器上有 Visual Studio Code,我正在制作一个新的 Scrapy Crawler.爬虫工作正常,但我想调试代码,为此我将其添加到我的 launch.json 文件中:

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"
    ]
}

但是我无法达到任何断点.PS:我从这里获取了 JSON 脚本:http://www.stevetrefethen.com/blog/debugging-a-python-scrapy-project-in-vscode

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

推荐答案

为了执行典型的 scrapy runspider 命令,您必须在 launch 中设置以下配置.json:

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.

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

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