Valkyrie0512
Valkyrie0512

Reputation: 119

Web scraping HTML in a Rails app

I'm trying to get my rails app to fetch the HTML source of a web page.

I want to get all of the HTML from a URI like /news_articles/7 into a string.

I tried using something like Nokogiri but it seems to lock mutex.

The purpose for this is to send a string of HTML to Amazon's SES.

Thanks

Upvotes: 1

Views: 490

Answers (1)

davegson
davegson

Reputation: 8331

Nokogiri in combination with Mechanize will serve you well.

Gemfile

gem 'nokogiri'
gem 'mechanize'

controller

agent = Mechanize.new()
# allow the agent to follow redirects
agent.follow_meta_refresh = true
# get the desired page
page = agent.get('http://www.mysite.com/new_articles/7')
# output its html
page.body

Possible Duplicate

Upvotes: 2

Related Questions