如何在rails中动态获取页面的视图源

时间:2014-10-20 05:58:42

标签: ruby-on-rails ruby

 i want to get the view source of this page "http://localhost:3000/splash_templates/edit_template/10017".

我使用了httpclient gem,但是我正在获取登录页面的视图源。    那么如何设置身份验证以及如何获取视图源

2 个答案:

答案 0 :(得分:0)

我之前没有使用它,但你需要首先验证用户身份然后获取内容。

http://www.rubydoc.info/gems/httpclient/2.1.5.2/HTTPClient此网址会对您有所帮助。 Configuring authentication credentials部分提供了授权用户运行时的方法。

希望这对你有帮助!

答案 1 :(得分:0)

您需要登录才能获取网页的来源。 虽然您的问题不清楚要求设置哪种身份验证,但是这里提示您可以继续

Authentication with Web server. Supports BasicAuth, DigestAuth, and Negotiate/NTLM        (requires ruby/ntlm module).
clnt = HTTPClient.new
domain = 'http://dev.ctor.org/http-access2/'
user = 'user'
password = 'user'
clnt.set_auth(domain, user, password)
p clnt.get_content('http://dev.ctor.org/http-access2/login').status

您可以阅读有关此Here

的更多信息

希望有所帮助;)