2 回答
TA贡献1817条经验 获得超14个赞
另一种方法。
import csv,os
import itertools
from simplified_scrapy import Spider, SimplifiedMain, utils
class ImageSpider(Spider):
name = 'images'
start_urls = []
def __init__(self):
with open('E:/Chris/imgUrls.csv') as csvDataFile:
csvReader = csv.reader(csvDataFile)
for elem in itertools.islice(csvReader, 0, 10):
self.start_urls.append(elem[0])
Spider.__init__(self,self.name) # Necessary
if(not os.path.exists('images/')):
os.mkdir('images/')
def afterResponse(self, response, url, error=None, extra=None):
try:
utils.saveResponseAsFile(response,'images/','image')
except Exception as err:
print (err)
return None
SimplifiedMain.startThread(ImageSpider()) # Start download
添加回答
举报