I am working on my first web scraping project and am trying to write my dataset to a .csv file. Writing string to the .csv seems to work fine:
fieldnames = ['fname', 'lname', 'image']
with open('dataset.csv', 'w', encoding='UTF8', newline='') as f:
newrow = {'fname': 'John', 'lname': 'Doe'}
writer.writerow(newrow)
But I also have a list of image urls that I would like to download to the .csv file as .pngs. When I try and do this, however, the image is written to the .csv as a string with this format '<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=120x159 at 0x7FC0A0...>'
Here is the code I have written to do this:
response = requests.get('someurl')
image_bytes = io.BytesIO(response.content)
img = PIL.Image.open(image_bytes)
newrow = {'image': img}
writer.writerow(newrow)
I'm not sure how I can get the actual .pngs to save to the csv file.