I used beautiful soup to scrape and extract images from a website describe below successfully but when I viewed the extracted images they appear as Url as shown below. I then experience difficulty in attempting to save the scraped image to my django database as a particular error shown below keeps on appearing. After I got the error I also tried using a forloop to create the post because I thought am trying to save a list element in a single data but it still shown the same or I got the same error not commited but when I remove the image scrape data from the file in title, summary, content and try to save to django database.it was a success. Saving image is the problem and I need help
Below is my sample code
My scraped images appear as a list of url as shown below
https://people.net/wp-content/uploads/2021/03/ad1-746x375.jpg https://people.net/wp-content/uploads/2020/08/caroon-1-600x375.jpg
something like this brought the images
images = [i['data-src'] for i in soup.find_all('img', {'class','attachment-jnews-750x375 size-jnews-750x375 lazyload wp-post-image'})]
but am unable to save the images scraped above like this because it will bring an error
Post.objects.create(
title=title,
content_1=paragraphs,
image=images,
sources=lnk,
)
this will bring an error when i try saving to models
class Post(models.Model):
title = models.CharField(max_length=250, blank = True, help_text='Maximum 160 Title characters.')
image = models.FileField(upload_to='images', blank=True, null=True, help_text='You must upload original image before continuing.')
if file and not file._committed: AttributeError: 'list' object has no attribute '_committed'
and I try using for loop but the same error exist too
for image in images:
/ Post.objects.create(title=title,
content_1=paragraphs,
image=images,
sources=lnk,
)
and I got this error also
if file and not file._committed: AttributeError: 'list' object has no attribute '_committed'