ruby-readability
ruby-readability copied to clipboard
HTML of the content extracted
main content of the article is extracted using .content. But how can the main content of article be extracted in the same css format?
So you want it to figure out the main content area, but not strip any HTML?
Actually, when i do .content, it works well but does not retain images in the main content. How can i extract main content along with the images. For example, I wanted to extract the main content of http://algs4.cs.princeton.edu/22mergesort/. It extracts but does not keep the images. How can this be achieved?
In short, can i extract the main content while keeping most of the format and content as it is.
Have you tried to pass a list of all tags that you want to keep into :tags
?
Hmm yes i have. For example to extract the main content of https://www.cs.auckland.ac.nz/~jmor159/PLDS210/qsort.html, i have used
source = open('https://www.cs.auckland.ac.nz/~jmor159/PLDS210/qsort.html').read y = Readability::Document.new(source,:tags => %w[p div pre img h1 h2 h3 h4 li ul tt em b a ol blockquote center br table td tr tbody font i dl dt dd], :attributes => %w[href rowspan border color src bgcolor width size align face]).content
but the result does not contain the image and sideby code.
Is there a way to extract everything of the main content?
You could try calling prepare_candidates
instead of content
, then looking at the value of best_candidate
. This is a port of the JavaScript readability library, so it's (originally) intended for cleaning out content and making readable text. That said, it would be useful to make it easier to just return the primary content region in-full.
I tried calling prepare_candidates, but it gave a single element. I am not getting what you are saying. There are times when some img or tables is being missed out of the content. Can this be tailored?
prepare_candidates
gave a single element, or calling best_candidate
did after having called prepare_candidates?
Hi,
I applied .content on http://www.algolist.net/Algorithms/Sorting/Bubble_sort . I got fairly good content but images were not coming. Is there a way to get them ?
Did you include img
in :tags
? There is also a call to get images. See https://github.com/cantino/ruby-readability#images
Sorry to sound repetitive but this may be due to #51 perhaps?