だから始めましょう。 linux/macを使うと仮定します。
$ cat /Users/tarun.lalwani/.virtualenvs/myproject/bin/scrapy
#!/Users/tarun.lalwani/.virtualenvs/myproject/bin/python3.6
# -*- coding: utf-8 -*-
import re
import sys
from scrapy.cmdline import execute
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(execute())
のは、このファイルの内容を見てみましょう私たちは
$ which scrapy
/Users/tarun.lalwani/.virtualenvs/myproject/bin/scrapy
をscrapyどこのは、確認してみましょうこれはcmdline.py
からexecute
方法を実行し、彼女はあなたの主な方法です。あなたがこの方法を実行気づけば
cmdline.py
from __future__ import print_function
....
....
def execute(argv=None, settings=None):
if argv is None:
argv = sys.argv
# --- backwards compatibility for scrapy.conf.settings singleton ---
if settings is None and 'scrapy.conf' in sys.modules:
from scrapy import conf
if hasattr(conf, 'settings'):
settings = conf.settings
# ------------------------------------------------------------------
if settings is None:
settings = get_project_settings()
# set EDITOR from environment if available
try:
editor = os.environ['EDITOR']
except KeyError: pass
else:
settings['EDITOR'] = editor
check_deprecated_settings(settings)
# --- backwards compatibility for scrapy.conf.settings singleton ---
import warnings
from scrapy.exceptions import ScrapyDeprecationWarning
with warnings.catch_warnings():
warnings.simplefilter("ignore", ScrapyDeprecationWarning)
from scrapy import conf
conf.settings = settings
# ------------------------------------------------------------------
inproject = inside_project()
cmds = _get_commands_dict(settings, inproject)
cmdname = _pop_command_name(argv)
parser = optparse.OptionParser(formatter=optparse.TitledHelpFormatter(), \
conflict_handler='resolve')
if not cmdname:
_print_commands(settings, inproject)
sys.exit(0)
elif cmdname not in cmds:
_print_unknown_command(settings, cmdname, inproject)
sys.exit(2)
cmd = cmds[cmdname]
parser.usage = "scrapy %s %s" % (cmdname, cmd.syntax())
parser.description = cmd.long_desc()
settings.setdict(cmd.default_settings, priority='command')
cmd.settings = settings
cmd.add_options(parser)
opts, args = parser.parse_args(args=argv[1:])
_run_print_help(parser, cmd.process_options, args, opts)
cmd.crawler_process = CrawlerProcess(settings)
_run_print_help(parser, _run_command, cmd, args, opts)
sys.exit(cmd.exitcode)
if __name__ == '__main__':
execute()
は今、それはあなたによって渡される引数を処理します。あなたのケースではcrawl quotes
です。実行メソッドは、クラスのプロジェクトをスキャンし、名前がquotes
と定義されているかどうかを調べます。それはCrawlerProcess
クラスを作成し、それはショー全体を実行します。
ScrapyはツイストPythonのフレームワークに基づいています。スケジューラベースのフレームワークです。エンジンがこの機能を実行し、最初の収率が実行されたとき
コード
for url in urls:
yield scrapy.Request(url=url, callback=self.parse)
の下部分を考えます。値はエンジンに戻されます。エンジンは現在、保留中の他のタスクを実行します(それらが発生すると、他の保留中のタスクキュー関数がチャンスを得る)。したがって、yield
は、関数の実行をパーツに分割し、Scrapy/Twistedの作業を支援するものです。
あなたは下のリンクに関する詳細な概要を得ることができます
https://doc.scrapy.org/en/latest/topics/architecture.html