ruby-readability
ruby-readability copied to clipboard
How to captured image when I used Readability::Document.new(source).content?
You can do .images
instead of .content
.
If you mean you want the images to be embedded inside the content you can also try setting the option:
{
tags: YOUR_TAGS + %w(img),
remove_empty_nodes: false
}
You may need to add src
to the list of attributes as well.
When importing content from medium.com you need to add "figure" to allowed tags
@haluan, is it solved for you?
I have the same problem. Adde img and remove_empty_nodes: false are doing nothing and still the images are still being removed from content.
url = "https://medium.com/better-advice/20-things-most-people-learn-too-late-in-life-23674cdbd75c"
body = open(url).read
rbody = Readability::Document.new(body, :tags => %w[div p img a figure], :attributes => %w[src href figure], :remove_empty_nodes => false).content
rbody.content