質問編集履歴

1

試したことを追加しました。

2022/02/13 04:27

投稿

ymwtskm
ymwtskm

スコア23

test CHANGED
File without changes
test CHANGED
@@ -17,3 +17,31 @@
17
17
  reactor.run() # the script will block here until the crawling is finished
18
18
  ```
19
19
 
20
+ ■試したこと
21
+ 下記リンクにある以下のコードを試しましたが、csvファイルは出力されたものの、データが格納されていませんでした。
22
+ [Scrapyのクローリング処理を外部のスクリプトから実行する](https://note.nkmk.me/python-scrapy-from-script/)
23
+ ```ここに言語を入力
24
+ from twisted.internet import reactor, defer
25
+ from scrapy.crawler import CrawlerRunner
26
+ from scrapy.utils.log import configure_logging
27
+ from scrapy.utils.project import get_project_settings
28
+
29
+ settings = get_project_settings()
30
+
31
+ settings.set('FEED_URI', 'results/search_%(filename)s_%(rank)s.csv')
32
+
33
+ configure_logging()
34
+ runner = CrawlerRunner(settings)
35
+
36
+
37
+ @defer.inlineCallbacks
38
+ def crawl():
39
+ yield runner.crawl('search_args', query='python', rank=0, comment='test', filename='python')
40
+ yield runner.crawl('search_args', query='ruby', rank=0, comment='test', filename='ruby')
41
+ reactor.stop()
42
+
43
+
44
+ crawl()
45
+ reactor.run()
46
+ ```
47
+ なお、scrapy crawl ○○ -o hello.csv のコマンドからは出力できています。