With Nokogiri I am Getting Error "Initialize': Getaddrinfo: No Such Host Is Known. (Socketerror)"

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



Leave a reply



Submit