I'm having a little trouble using Readability - I tried using the ruby-readability
gem and following the instructions on GitHub but the site I am tryin开发者_开发知识库g to use it on is causing character encoding problems (http://en.wikipedia.org/wiki/MDMA).
Then I tried using the actual readability website: http://www.readability.com/api/content/v1/parser?url=http://en.wikipedia.org/wiki/MDMA&token=my_token_here and it returned a page with the following information:
Ideal Answer: Step-by-Step: How to use ruby-readability gem to read this website in particular (it works for other websites)
Secondary Answer: How to access params[:content]
for that site (in the pic is displays the value of content, which is what I want).
If you need me to clarify any part of the question please let me know!
Thanks!!
Used examples from https://github.com/iterationlabs/ruby-readability
Make sure the gem is installed and required in your Gemfile. Then, from what it looks like you're trying to do:
require 'rubygems'
require 'readability'
require 'open-uri'
# 1. Fetch the content of the site. open() requests the document
# and read() passes you the page content.
source = open('http://en.wikipedia.org/wiki/MDMA').read
# 2. Pass the content to the Readability gem to do its magic.
puts Readability::Document.new(source).content
精彩评论