Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML of the content extracted #59

Open
papriwalprateek opened this issue Jan 15, 2014 · 11 comments
Open

HTML of the content extracted #59

papriwalprateek opened this issue Jan 15, 2014 · 11 comments

Comments

@papriwalprateek
Copy link

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

@cantino
Copy link
Owner

cantino commented Jan 15, 2014

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

@papriwalprateek
Copy link
Author

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
Copy link
Author

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

@cantino
Copy link
Owner

cantino commented Jan 16, 2014

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

@papriwalprateek
Copy link
Author

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?

@cantino
Copy link
Owner

cantino commented Jan 16, 2014

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.

@papriwalprateek
Copy link
Author

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?

@cantino
Copy link
Owner

cantino commented Jan 17, 2014

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

@papriwalprateek
Copy link
Author

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 ?

@cantino
Copy link
Owner

cantino commented Jan 21, 2014

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

@pagojo
Copy link
Contributor

pagojo commented Jan 22, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants