ruby-readability icon indicating copy to clipboard operation
ruby-readability copied to clipboard

HTML of the content extracted

Open papriwalprateek opened this issue 11 years ago • 11 comments

main content of the article is extracted using .content. But how can the main content of article be extracted in the same css format?

papriwalprateek avatar Jan 15 '14 15:01 papriwalprateek

So you want it to figure out the main content area, but not strip any HTML?

cantino avatar Jan 15 '14 23:01 cantino

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?

papriwalprateek avatar Jan 16 '14 03:01 papriwalprateek

In short, can i extract the main content while keeping most of the format and content as it is.

papriwalprateek avatar Jan 16 '14 03:01 papriwalprateek

Have you tried to pass a list of all tags that you want to keep into :tags?

cantino avatar Jan 16 '14 04:01 cantino

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?

papriwalprateek avatar Jan 16 '14 05:01 papriwalprateek

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.

cantino avatar Jan 16 '14 05:01 cantino

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?

papriwalprateek avatar Jan 17 '14 11:01 papriwalprateek

prepare_candidates gave a single element, or calling best_candidate did after having called prepare_candidates?

cantino avatar Jan 17 '14 19:01 cantino

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 ?

papriwalprateek avatar Jan 21 '14 18:01 papriwalprateek

Did you include img in :tags? There is also a call to get images. See https://github.com/cantino/ruby-readability#images

cantino avatar Jan 21 '14 23:01 cantino

Sorry to sound repetitive but this may be due to #51 perhaps?

pagojo avatar Jan 22 '14 10:01 pagojo