Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7925741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:26:02+00:00 2026-06-03T18:26:02+00:00

I want to be able to run the Scrapy web crawling framework from within

  • 0

I want to be able to run the Scrapy web crawling framework from within Django. Scrapy itself only provides a command line tool scrapy to execute its commands, i.e. the tool was not intentionally written to be called from an external program.

The user Mikhail Korobov came up with a nice solution, namely to call Scrapy from a Django custom management command. For convenience, I repeat his solution here:

# -*- coding: utf-8 -*-
# myapp/management/commands/scrapy.py 

from __future__ import absolute_import
from django.core.management.base import BaseCommand

class Command(BaseCommand):

    def run_from_argv(self, argv):
        self._argv = argv
        return super(Command, self).run_from_argv(argv)

    def handle(self, *args, **options):
        from scrapy.cmdline import execute
        execute(self._argv[1:])

Instead of calling e.g. scrapy crawl domain.com I can now do python manage.py scrapy crawl domain.com from within a Django project. However, the options of a Scrapy command are not parsed at all. If I do python manage.py scrapy crawl domain.com -o scraped_data.json -t json, I only get the following response:

Usage: manage.py scrapy [options] 

manage.py: error: no such option: -o

So my question is, how to extend the custom management command to adopt Scrapy’s command line options?

Unfortunately, Django’s documentation of this part is not very extensive. I’ve also read the documentation of Python’s optparse module but afterwards it was not clearer to me. Can anyone help me in this respect? Thanks a lot in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T18:26:03+00:00Added an answer on June 3, 2026 at 6:26 pm

    Okay, I have found a solution to my problem. It’s a bit ugly but it works. Since the Django project’s manage.py command does not accept Scrapy’s command line options, I split the options string into two arguments which are accepted by manage.py. After successful parsing, I rejoin the two arguments and pass them to Scrapy.

    That is, instead of writing

    python manage.py scrapy crawl domain.com -o scraped_data.json -t json
    

    I put spaces in between the options like this

    python manage.py scrapy crawl domain.com - o scraped_data.json - t json
    

    My handle function looks like this:

    def handle(self, *args, **options):
        arguments = self._argv[1:]
        for arg in arguments:
            if arg in ('-', '--'):
                i = arguments.index(arg)
                new_arg = ''.join((arguments[i], arguments[i+1]))
                del arguments[i:i+2]
                arguments.insert(i, new_arg)
    
        from scrapy.cmdline import execute
        execute(arguments)
    

    Meanwhile, Mikhail Korobov has provided the optimal solution. See here:

    # -*- coding: utf-8 -*- 
    # myapp/management/commands/scrapy.py 
    
    from __future__ import absolute_import
    from django.core.management.base import BaseCommand
    
    class Command(BaseCommand):
    
        def run_from_argv(self, argv):
            self._argv = argv
            self.execute()
    
        def handle(self, *args, **options):
            from scrapy.cmdline import execute
            execute(self._argv[1:])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to run my Python project from the command line.
I want to be able to run a command from my machine using ssh
I want to be able to run a program through command line and I
In Ruby, I want to be able to: run a command line (via shell)
I want to be able to run external shell tools from within Eclipse, especially
As the topic says, I want to be able to run a specific command
Problem: I want to be able to run a bash instance from my cocoa
I'm writing a micro MVC framework, and I want to be able to run
I want to be able to run netstat -n and grab the output somehow
Is there any drawback to this setup? I want to be able to run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.