हाँ और नहीं [1]। यदि आप एक पीडीएफ लाते हैं तो इसे स्मृति में संग्रहीत किया जाएगा, लेकिन यदि पीडीएफ आपकी उपलब्ध मेमोरी को भरने के लिए पर्याप्त नहीं हैं तो यह ठीक है।
आप मकड़ी कॉलबैक में पीडीएफ को बचा सकता है:
def parse_listing(self, response):
# ... extract pdf urls
for url in pdf_urls:
yield Request(url, callback=self.save_pdf)
def save_pdf(self, response):
path = self.get_path(response.url)
with open(path, "wb") as f:
f.write(response.body)
आप एक पाइप लाइन में यह करने के लिए चुनते हैं:
# in the spider
def parse_pdf(self, response):
i = MyItem()
i['body'] = response.body
i['url'] = response.url
# you can add more metadata to the item
return i
# in your pipeline
def process_item(self, item, spider):
path = self.get_path(item['url'])
with open(path, "wb") as f:
f.write(item['body'])
# remove body and add path as reference
del item['body']
item['path'] = path
# let item be processed by other pipelines. ie. db store
return item
[1] एक और दृष्टिकोण केवल दुकान pdfs 'यूआरएल हो सकता है और स्मृति में बफर किए बिना दस्तावेजों को लाने के लिए एक और प्रक्रिया का उपयोग करें। (wget
जैसे)
एक FilesPipeline है कि आप सीधे उपयोग कर सकते हैं, यह मानते हुए आप पहले से ही फ़ाइल यूआरएल है, लिंक
FilesPipeline उपयोग करने के लिए कैसे पता चलता
क्यों बल्कि एक FEED_EXPORTER का उपयोग नहीं कर एक से पाइपलाइन? –