Rails -- 从 HTTP 请求获取哈希响应(可读性 url)

发布于 2024-11-27 12:15:09 字数 845 浏览 0 评论 0原文

我在使用 Readability 时遇到了一些麻烦 - 我尝试使用 ruby​​-readability gem 并遵循 GitHub 上的说明,但我尝试使用它的网站导致字符编码问题(http://en.wikipedia.org/wiki/MDMA)。

然后我尝试使用实际的可读性网站: http://www.readability.com/api/content/v1/parser?url=http://en.wikipedia.org/wiki/MDMA&token=my_token_here 它返回了一个包含以下信息的页面:

在此处输入图像描述

理想答案:逐步:如何使用ruby-readability gem 特别阅读这个网站(它适用于其他网站)

第二个答案:如何访问该网站的 params[:content] (在图片中显示内容的值,其中是我想要的)。

如果您需要我澄清问题的任何部分,请告诉我!

谢谢!!

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 trying 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:

enter image description here

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!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伪心 2024-12-04 12:15:09

使用的示例来自 https://github.com/iterationlabs/ruby-readability

确保 gem 是在 Gemfile 中安装并需要。然后,从你正在尝试做的事情来看:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文