0

Iam trying to extract image from content, with beautifulsoup or python or anything.

I tried using python goose but I'm not getting much help for this so I'm thinking to switch my tool to achieve this job.

I'm using wyswyg editor named django-ckeditor.

users make content through this editor which is being saved as a content field in my Post model. To display that, all I had to do was {{post.content}} content users can post are image and text.

Now I want to display the image separately from the content. I want to thumbnail the image that's in content.

I used python goose to achieve this as I have some experience with this. I'm not sure why it's not working this time.

Here's my code

from django.db import models
from ckeditor_uploader.fields import RichTextUploadingField


class Post(models.Model):
    title = models.CharField(max_length = 100)
    content = RichTextUploadingField(config_name='default')
    @property

    def thumbnail(self, content):
        g = Goose()
        thumbnail = g.extract(raw_html=self.content).top_image.src
        return thumbnail

in html file

<img src="{{ post.thumbnail }}" />

nothing shows up.

How do I extract images from the content?

Martin Gergov
  • 1,556
  • 4
  • 20
  • 29
lip123809
  • 89
  • 7
  • Here is a link to get images from the website- http://stackoverflow.com/questions/18304532/extracting-image-src-based-on-attribute-with-beautifulsoup – Dlucidone Feb 02 '16 at 12:25
  • @Dlucidone yeah but I'm not getting images from other site, i'm trying to extract images from content field – lip123809 Feb 02 '16 at 12:41

0 Answers0