user@domain.invalid
9/12/2006 11:50:00 AM
le 12/09/2006 13:09, William Crawford nous a dit:
>
> Another thought, however. Perhaps the page has additional requirements
> that you haven't met. Cookies that don't exist on the other page, but
> were set at login or somewhere else. Headers that you aren't sending
> and it expects. A specific refering page. (Or something else I've
> momentarily forgotten.)
>
I don't why but suddenly it worked... I presumed I've missed something
somewhere..
Now, I've rewritten the code and I use a "write-once" cookie mechanism
which is generic for every "scrapping" class that I use - It's
sufficient for now
def http_get(url)
headers = Hash.new()
headers['User-agent'] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows
NT 5.1)"
headers['Cookie'] = @cookies unless @cookies.nil?
response = @http.get(url, headers)
raise "url #{url} no access on host #{@host}:#{@port} - code
#{response.code}" if not ['200','302'].include?(response.code)
@cookies = response.response['set-cookie'] if @cookies.nil?
response.body
end
Just for my own education, could this code be rewriten in a more elegant
way ?
Thanks