如何使用Ruby解析没有响应标头的HTML响应 [英] How can I Parse an HTML response without response headers using Ruby
问题描述
在没有响应头的情况下如何获取HTML响应?
How can I grab an HTML response when there are no response headers?
我有这个:
require 'hpricot'
require 'open-uri'
doc = Hpricot(open('http://192.168.100.1/phy.htm'))
在这种情况下,服务器是不返回HTTP响应标头的电缆调制解调器.
The server in this case is a cable modem that is not returning HTTP Response headers.
上面的代码失败并显示:
The above code is failing with:
C:/Ruby/lib/ruby/1.8/net/http.rb:2022:在'read_status_line'中:错误的状态行: (Net :: HTTPBadResponse)
C:/Ruby/lib/ruby/1.8/net/http.rb:2022:in `read_status_line': wrong status line: "" (Net::HTTPBadResponse)
来自C:/Ruby/lib/ruby/1.8/net/http.rb:2009:位于"read_new"中
from C:/Ruby/lib/ruby/1.8/net/http.rb:2009:in `read_new'
来自C:/Ruby/lib/ruby/1.8/net/http.rb:1050:在'request'中
from C:/Ruby/lib/ruby/1.8/net/http.rb:1050:in `request'
从C:/Ruby/lib/ruby/1.8/open-uri.rb:248:在'open_http'中
from C:/Ruby/lib/ruby/1.8/open-uri.rb:248:in `open_http'
推荐答案
因此,如果您的服务器不符合HTTP规范,也许您应该完全放弃HTTP想法并直接与Socket
一起使用...
So if your server is not HTTP compliant, maybe you should drop HTTP idea altogether and work with Socket
directly...
然后,您可以将hpricot与返回的字符串一起使用.
Then you can use hpricot with a string returned.
这篇关于如何使用Ruby解析没有响应标头的HTML响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!