2014-03-26 58 views
0

我試圖讓我的Rails應用程序獲取網頁的HTML源代碼。Web抓取Rails應用程序中的HTML

我想從一個URI如/news_articles/7獲得所有的HTML到一個字符串。

我嘗試使用類似Nokogiri的東西,但它似乎鎖定互斥鎖。

這樣做的目的是將一串HTML發送到亞馬遜的SES

感謝

+0

1)我不能分析你的** ......讓所有的HTML的URI ... * *。 2)什麼是Nokugiri? 3)**看起來** =>看起來4)**原因** =>目的 – sawa

+0

你可以直接進入你的應用,右鍵單擊並查看源代碼? –

+1

您可能希望在SES中使用類似'ActionMailer'的東西,而不是嘗試將頁面呈現爲字符串。 http://stackoverflow.com/questions/4798437/using-amazon-ses-with-rails-actionmailer – Casper

回答

1

Nokogiri結合Mechanize將竭誠爲您服務好。

的Gemfile

gem 'nokogiri' 
gem 'mechanize' 

控制器

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

+0

我認爲他正在嘗試從Rails請求週期內運行此操作。因此他會使整個Rails應用程序陷入僵局。這是他的主要問題。 – Casper

+0

Jup更有意義,我想你提供了正確的鏈接 –