def run(self):
while True:
# The name will be used for saving the file
name, url = self.imageQueue.get()
res = requests.get(url, headers=HEADERS, timeout=TIMEOUT, stream=True)
if res.status_code == 200:
content_type = res.headers['content-type']
# With the content type received from the web server, use mimetypes to guess the file extension.
extension = mimetypes.guess_extension(content_type)
filepath = os.path.join('./' + IMAGE_FOLDER + '/' + name + extension)
with open(filepath, 'wb') as f:
# Stream the files.
for chunk in res:
f.write(chunk)
# Notify that we have finished one task.
self.imageQueue.task_done()
# Function to retrieve a list of URL for every pages of cards.
# The url parameter is the entry point of the website where we might extract the information.
评论列表
文章目录