How to use PyCharm to debug Scrapy projects

后端 未结 10 1399
长发绾君心
长发绾君心 2020-12-02 04:00

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?

<
10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 04:24

    According to the documentation https://doc.scrapy.org/en/latest/topics/practices.html

    import scrapy
    from scrapy.crawler import CrawlerProcess
    
    class MySpider(scrapy.Spider):
        # Your spider definition
        ...
    
    process = CrawlerProcess({
        'USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'
    })
    
    process.crawl(MySpider)
    process.start() # the script will block here until the crawling is finished
    

提交回复
热议问题