How can I parse a URL using a proxy with Rails?

别说谁变了你拦得住时间么 提交于 2020-01-14 10:30:12

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/29680726/how-can-i-parse-a-url-using-a-proxy-with-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!