2017-01-07 6 views
0

안녕하십니까. 일부 웹 사이트에서 뉴스를 가져 오는 작은 웹 크롤러를 만들고 있습니다. 나는 Typhoeus를 사용하고 있습니다.캐시 된 html을 막기 위해 크롤러에 적합한 헤더를 설정하십시오.

내 코드는 다음과 같다 :

request = Typhoeus::Request.new(url, timeout: 60) 
request.on_complete do |response| 
    doc = Nokogiri::HTML(response.body) 
    root_url = source.website.url 
    links = doc.css(css_selectors).take(20) 
end 
hydra.queue(request) 
hydra.run 

문제는 일부 웹 사이트 요청이 페이지의 chached 이전 버전을 반환합니다. 나는 헤더를 설정하고 "Cache-Control"=> 'no-cache'를 포함 시켰지만 도움이되지 않았습니다! 도움이 될 것입니다.

open-uri를 사용할 때도 같은 일이 발생합니다. 웹 사이트의 reponse 헤더의

하나

{"Server"=>"nginx/1.10.2", "Date"=>"Sat, 07 Jan 2017 12:43:54 GMT", "Content-Type"=>"text/html; charset=utf-8", "Transfer-Encoding"=>"chunked", "Connection"=>"keep-alive", "X-Drupal-Cache"=>"MISS", "X-Content-Type-Options"=>"nosniff", "Etag"=>"\"1483786108-1\"", "Content-Language"=>"ar", "Link"=>"</taxonomy/term/1>; rel=\"shortlink\",</Actualit%C3%A9s>; rel=\"canonical\"", "X-Generator"=>"Drupal 7 (http://drupal.org)", "Cache-Control"=>"public, max-age=0", "Expires"=>"Sun, 19 Nov 1978 05:00:00 GMT", "Vary"=>"Cookie,Accept-Encoding", "Last-Modified"=>"Sat, 07 Jan 2017 10:48:28 GMT", "X-Cacheable"=>"YES", "X-Served-From-Cache"=>"Yes"} 

답변

0

이 작동합니다 :

"Cache-Control" => 'no-cache, no-store, must-revalidate' 
"Pragma" => 'no-cache' 
"Expires" => '0' 
+0

작동하지 않았다 – mma7