Have a look at the open_uri_redirections gem. It patches Ruby's OpenURI to allow redirections from HTTP to HTTPS or the other way around....
ruby-on-rails,ruby,xpath,nokogiri,open-uri
The problem is with your use of single quotes instead of double quotes. change this: title = page.xpath('//span[@class="tit"][#{x}]').inner_html to this: title = page.xpath("//span[@class=\"tit\"][#{x}]").inner_html for proper variable expansion. Note also the escaping of internal double quotes....
ruby-on-rails,ruby,ruby-on-rails-4,open-uri
Check result of meta method: p obj.meta probably in have Content-Disposition header. In this case it can have file name as optional parameter....
ruby-on-rails,facebook,facebook-graph-api,open-uri,omniauth-facebook
Thanks for the answer, Yes i could use the paperclip gem but i'm already using cloudinary to upload image so i didn't wanted to use another image based gem just to force save files from fb user profile. I was able to workout the following code changes. In omniauth.rb :secure_image_url...
ruby,json,hash,tumblr,open-uri
What you're really asking is how to access values in a hash. I'm sure there's plenty of precedent here on SO. But to get you started, here are some examples: jtest["meta"]["status"] #=> 200 jtest["response"]["blog"]["title"] #=> "Demo" At any point you can inspect the output. I like using pp to get...
ruby,web-scraping,nokogiri,net-http,open-uri
This is called content negotiation - the web server redirects based on your request. pt (Portuguese) seems to be the default: (at least from my location) $ curl -I https://www.zomato.com/grande-lisboa/fu-hao-massam%C3%A1 HTTP/1.1 301 Moved Permanently Set-Cookie: zl=pt; ... Location: https://www.zomato.com/pt/grande-lisboa/fu-hao-massam%C3%A1 You can request another language by sending an Accept-Language header. Here's...
ruby-on-rails,ruby,mechanize,open-uri
I think you'll want to use a Mechanize#start block: 10.times do Mechanize.start do |minion| minion.open_timeout = 15 minion.read_timeout = 15 minion.set_proxy '212.82.126.32', 80 page = minion.get("http://www.whatsmyip.org/") proxy_ip_adress = page.parser.css('#ip').text puts proxy_ip_adress end # minion definitely doesn't exist anymore end ...
Here is the modification according to the post and comment: require 'open-uri' def http_download(uri, filename) bytes_total = nil index = 1 begin open( uri, read_timeout: 500, content_length_proc: lambda { |content_length| bytes_total = content_length }, progress_proc: lambda { |bytes_transferred| if bytes_total print("\r#{bytes_transferred} of #{bytes_total} bytes") else print("\r#{bytes_transferred} bytes (total size unknown)")...