2017-09-22 8 views
0

이 질문을하기 전에 해결책을 모색했지만 불행히도 좋은 결과를 얻지 못했습니다. 또한 시도웹 페이지에서 구문 분석 결과 405가 허용되지 않음

require 'open-uri' 
doc = Nokogiri::HTML(open("http://streeteasy.com")) 

#=> OpenURI::HTTPError: 405 Not Allowed 
    from /Users/cyrusghazanfar/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/open-uri.rb:358:in `open_http' 

:

$ curl -I http://streeteasy.com 

반환

HTTP/1.1 405 Not Allowed 
Date: Fri, 22 Sep 2017 20:03:59 GMT 
Content-Type: text/html 
Connection: keep-alive 
Server: nginx 
X-DZ: 24.193.31.96 
Vary: Accept-Encoding 
X-DZ: 127.0.0.1 
Expires: Thu, 01 Jan 1970 00:00:01 GMT 
Cache-Control: private, no-cache, no-store, must-revalidate 
Edge-Control: no-store, bypass-cache 
Surrogate-Control: no-store, bypass-cache 

답변

3

문제가 서버가 작업 할 User-Agent 헤더를해야되는이 특정 URL에 액세스 할 때 은 내가 OpenURI::HTTPError: 405 Not Allowed를 얻을 수 , 곱슬 곱슬하게 그럴 것입니다 :

curl --header "User-Agent: Mozilla/5.0" http://streeteasy.com 
+0

고마워요. 그것은 내 직감이었다. nokogiri로 사용자 에이전트를 지정하는 방법을 알고 있습니까? – Cyzanfar

+0

실제로는 아니지만 정상적인 헤더를 추가하는 것과 같아야합니다. [이 링크] (https://stackoverflow.com/questions/12205221/python-mechanize-how-to-add-a-header-on-a-single -open-call) 당신을 도울 수 – eLRuLL

+0

내 요청에 user-agent를 추가했는데 내가 로봇이라고 생각하기 때문에 웹 사이트가 나를 차단한다는 것을 제외하고는 작동했습니다. – Cyzanfar