Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling scrapy from a python script not creating JSON output file
    primarykey
    data
    text
    <p>Here's the python script that i am using to call scrapy, the answer of </p> <p><a href="https://stackoverflow.com/questions/14777910/scrapy-crawl-from-script-always-blocks-script-execution-after-scraping">Scrapy crawl from script always blocks script execution after scraping</a></p> <pre><code>def stop_reactor(): reactor.stop() dispatcher.connect(stop_reactor, signal=signals.spider_closed) spider = MySpider(start_url='abc') crawler = Crawler(Settings()) crawler.configure() crawler.crawl(spider) crawler.start() log.start() log.msg('Running reactor...') reactor.run() # the script will block here until the spider is closed log.msg('Reactor stopped.') </code></pre> <p>here's my pipelines.py code</p> <pre><code>from scrapy import log,signals from scrapy.contrib.exporter import JsonItemExporter from scrapy.xlib.pydispatch import dispatcher class scrapermar11Pipeline(object): def __init__(self): self.files = {} dispatcher.connect(self.spider_opened , signals.spider_opened) dispatcher.connect(self.spider_closed , signals.spider_closed) def spider_opened(self,spider): file = open('links_pipelines.json' ,'wb') self.files[spider] = file self.exporter = JsonItemExporter(file) self.exporter.start_exporting() def spider_closed(self,spider): self.exporter.finish_exporting() file = self.files.pop(spider) file.close() def process_item(self, item, spider): self.exporter.export_item(item) log.msg('It reached here') return item </code></pre> <p>This code is taken from here</p> <p><a href="https://stackoverflow.com/questions/7839559/scrapy-issues-with-json-export">Scrapy :: Issues with JSON export</a></p> <p>When i run the crawler like this</p> <pre><code>scrapy crawl MySpider -a start_url='abc' </code></pre> <p>a links file with the expected output is created .But when i execute the python script it does not create any file though the crawler runs as the dumped scrapy stats are similar to those of the previous run. I think there's a mistake in the python script as the file is getting created in the first approach .How do i get the script to output the file ? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload