Пример #1
0
 def csv(self, filename, fields, row_list):
     '''保存到CSV'''
     try:
         with open(PathManage.crawler_path(filename), 'w', newline='') as f:
             writer = csv.writer(f)
             writer.writerow(fields)
             for row in row_list:
                 writer.writerow(row)
         return {'status': 0, 'statusText': 'csv saved'}
     except Exception:
         return {'status': 1, 'statusText': 'csv error'}
Пример #2
0
 def save_images(self, image_list):
     for img in image_list[:self.limit]:
         print('保存:', img.get_attribute('alt'))
         filename = img.get_attribute('alt') + '.jpg'
         with open(PathManage.crawler_path(filename), 'wb') as f:
             f.write(requests.get(img.get_attribute('src')).content)