I'm following this answer to get the spider list on my Scrapy Project inside Django, so this is what the structure looks like.
my_app/
-- apps/ # django apps folder
-- crawler/
-- __init__.py
-- admin.py
-- apps.py
-- views.py <~ here is where the code below located
-- etc..
-- my_app/ # django project folder
-- __init__.py
-- asgi.py
-- settings.py
-- etc..
-- scraper_app/ # scrapy dir
-- scraper_app/ # scrapy project folder
-- spiders/
-- abc_spider.py
-- __init__.py
-- middlewares.py
-- pipelines.py
-- settings.py
-- etc..
-- scrapy.cfg
-- manage.py
-- scrapyd.conf
-- setup.py
-- etc..
and here is the piece of codes that showing the list of available spiders, when I run it on scrapy shell
, but its always return an empty string when I tried to run it from django app in views.py
, which is crawler app.
project_settings = project.get_project_settings()
spider_loader = spiderloader.SpiderLoader.from_settings(project_settings)
spiders = spider_loader.list()
so my problem is, how to make those script working on django project as well using Django or Scrapy way if available? thanks
EDITED
I just realized that when I tried to get the values from project.get_project_settings()
in scrapy shell it'll return with
'SPIDER_MODULES': ['scraper_app.spiders']
but when I tried to run it from django, the SPIDER_MODULES
return an empty list