pipelines.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. # Define your item pipelines here
  3. #
  4. # Don't forget to add your pipeline to the ITEM_PIPELINES setting
  5. # See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
  6. import json
  7. import requests
  8. import datetime
  9. class AirHistoryPipeline(object):
  10. def open_spider(self, spider):
  11. self.file = open('area.json', 'w')
  12. def process_item(self, item, spider):
  13. context = json.dumps(dict(item),ensure_ascii=False) + '\n'
  14. self.file.write(context)
  15. return item
  16. def close_spider(self,spider):
  17. self.file.close()
  18. class ManhuaPipeline(object):
  19. def process_item(self, item, spider):
  20. return item
  21. #
  22. class mmonlyPipeline(object):
  23. def process_item(self, item, spider):
  24. count = 0
  25. detailURL = item['detailURL']
  26. fileName = item['fileName']
  27. # print('5555555',detailURL)
  28. # print( fileName)
  29. image = requests.get(detailURL)
  30. # print('777777',image)
  31. f= open(fileName, 'wb')
  32. f.write(image.content)
  33. f.close()
  34. return item