我如何使用Rails使用代理解析URL? [英] How can I parse a URL using a proxy with Rails?
问题描述
我的应用有以下控制器操作:
def测试
#get URL
url =http://www.coteur.com/surebet.php
doc = Nokogiri :: HTML(open(url))
@show = doc.at_css(title) .text
@game_data = Array.new
doc.css('tbody')。each do | tr |
tr.css(tr)。each do | f |
@ game_data.push(f.css(td)。text)
end
end
end
并呈现以下视图:
< %= @ show%>
< div class =bs-exampledata-example-id =hoverable-table>
< table class =table table-hover>
< tbody>
<%如果@ game_data.empty? %GT;
< tr>
< td> Nope< / td>
< / tr>
<%else%>
<%@ game_data.each do | game |%>
< tr>
< td><%=游戏%>< / td>
< / tr>
<%end%>
<%end%>
< / tbody>
< / table>
< / div>
一切工作都很好,但在Heroku上
<%= @ game_data% >
看起来应该是空的,而不应该是。问题是,在美国它不起作用,但在欧盟它却行。那么我该如何使用代理或更改服务器位置或其他方法来解决这个问题? 您可以将当前的Heroku应用程序进入欧洲地区:
$ heroku fork --region eu
创建fork myapp-332 ...完成
复制slu ... ...完成
复制配置变量...完成
完成叉,查看http://myapp-332.herokuapp.com/
现在您将拥有在欧洲运行的应用程序副本,这可能对您更好。如果有效,您可以保留新应用并关闭旧应用。
请参阅 fork application docs 获取更多细节。
My app has the following controller action:
def test #get URL url = "http://www.coteur.com/surebet.php" doc = Nokogiri::HTML(open(url)) @show = doc.at_css("title").text @game_data = Array.new doc.css('tbody').each do |tr| tr.css("tr").each do |f| @game_data.push(f.css("td").text) end end end
And render the following view:
<%= @show%> <div class="bs-example" data-example-id="hoverable-table"> <table class="table table-hover"> <tbody> <% if @game_data.empty? %> <tr> <td>Nope</td> </tr> <%else%> <% @game_data.each do |game|%> <tr> <td><%= game%></td> </tr> <%end%> <%end%> </tbody> </table> </div>
Everything work fine locally but on Heroku the
<%= @game_data%>
appears to be empty while it should not be. The problem is that in the US it does not work but in the EU it does. So how can I work this around with a proxy or changing the server location or something else ?解决方案You can fork your current Heroku app into the European region with:
$ heroku fork --region eu Creating fork myapp-332... done Copying slug... done Copying config vars... done Fork complete, view it at http://myapp-332.herokuapp.com/
Now you'll have a copy of your app running in Europe, which may work better for you. If that works you can keep the new app and shut down the old one.
See the fork application docs for more details.
这篇关于我如何使用Rails使用代理解析URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!