With Nokogiri i am getting error initialize': getaddrinfo: No such host is known. (SocketError)
It appears you need to configure a proxy. Find out what the proxy URL/Port is for your organization (and whether there needs to be authentication). You may be able to view this information from your browser configuration. In order to use it with your Ruby code, you need to set the HTTP_PROXY
environment variable.
You can set it in Ruby code:
ENV['HTTP_PROXY'] = 'http://hostname:port'
or if you need authentication:
ENV['HTTP_PROXY'] = 'http://username:password@hostname:port'
A more permanent solution is to set HTTP_PROXY
in your system environment variables.
Can't use RubyPress gem gives getaddrinfo: No such host is known. (SocketError)
host
must be a host name (e.g. "localhost"
in this particular case, or, say, "google.com"
):
require 'rubypress'
wp = Rubypress::Client.new(host: "localhost",
username: "admin",
password: "admin",
path: "/wordpress/xmlrpc.php")
Probably, you might need to tune the path
parameter up to point exactly to where WP’s RPC endpoint is to be found.
Can we use selenium-webdriver and nokogiri together?
You can get the source of the page from selenium-webdriver by using the page_source
method:
driver.page_source
So your script could be:
require 'selenium-webdriver'
require 'nokogiri'
driver = Selenium::WebDriver.for :firefox
driver.get "http://www.google.com/"
doc = Nokogiri::HTML(driver.page_source)
# Do whatever with nokogiri
That said, I do not know why you would want to use nokogiri instead of just selenium-webdriver.
How do I know what port I am using?
If you know your company's proxy settings (ask them, or look at your browser settings) then with open-uri
you can get through the firewall like this:
Nokogiri::HTML(open(url, :proxy => 'http://[proxy_host]:[proxy_port]'))
How to save pictures from URL to disk
You are almost done. The only thing left is to store files. Let’s do it.
LOCATION = 'C:\pickaxe\pictures'
if !File.exist? LOCATION # create folder if it is not exist
require 'fileutils'
FileUtils.mkpath LOCATION
end
require 'net/http'
.... # your code with nokogiri etc.
links.each{|link|
Net::HTTP.start(PAGE_URL) do |http|
localname = link.gsub /.*\//, '' # left the filename only
resp = http.get link['src']
open("#{LOCATION}/#{localname}", "wb") do |file|
file.write resp.body
end
end
end
That’s it.
SocketError: Failed to open TCP connection to rubygmes.org:443
rubygmes.org
seems to be misspelled in your Gemfile! Try rubygems.org
:)
Related Topics
Rails 3 - Has_And_Belongs_To_Many
Error Occurs When Trying to Install Homebrew on a MAC for Ruby on Rails
How to Print a Line Number in Ruby
How to Access Ruby Method Inside Module and Inside a Class from Another .Rb File
How to Remove Devise Password Resetting During Email Confirmation
Copy into Postgres with Arrays in Schema
Ruby String Prepend '\' Character
How to Collect Real-Time Tweets
Get Underlined Text with Markdown
Is It a Bad Idea Do Divide the Models into Directories
Ruby: How to Process a CSV File with "Bad Commas"
Why Does the Script Affect Everything on My Rails 3 App Even When Cased in This Code
How to Marshal a Hash with Arrays
Ruby Selenium Web Drive: How to Find Specific Element by Xpath Div Id and CSS Class
Calling Protected Class Method from Instance Method in Ruby
Why Can't I Create Active Records That Count for Something in Rspec