i start to learn ruby and scraping and i try to open an url with open and i got
lib/scrapper.rb:7:in `initialize': No such file or directory # rb_sysopen - https://en.wikipedia.org/wiki/Douglas_Adams (Errno::ENOENT) from lib/scrapper.rb:7:in `open' from lib/scrapper.rb:7:in `<main>'
And this is my code :
# frozen_string_literal: true
require 'rubygems'
require 'open-uri'
require 'nokogiri'
document = open("https://en.wikipedia.org/wiki/Douglas_Adams")
puts document
After some long hours of google research i don't find any solution ðŸ˜
I test open with this url to : http://www.krosmoz.com/fr/almanax
thanks all 🧅
ps i'm on mac m1 don't know if they are compatibility issues
The problem is likely that you are using ruby 3.0.0.
Under Ruby 2.7, I receive the following warning:
warning: calling URI.open via Kernel#open is deprecated, call URI.open directly or use URI#open
And under Ruby 3.0, it has been removed.
So the solution, per the warning:
document = URI.open("https://en.wikipedia.org/wiki/Douglas_Adams").read
Related
i start to learn ruby and scraping and i try to open an url with open and i got
lib/scrapper.rb:7:in `initialize': No such file or directory # rb_sysopen - https://en.wikipedia.org/wiki/Douglas_Adams (Errno::ENOENT) from lib/scrapper.rb:7:in `open' from lib/scrapper.rb:7:in `<main>'
And this is my code :
# frozen_string_literal: true
require 'rubygems'
require 'open-uri'
require 'nokogiri'
document = open("https://en.wikipedia.org/wiki/Douglas_Adams")
puts document
After some long hours of google research i don't find any solution ðŸ˜
I test open with this url to : http://www.krosmoz.com/fr/almanax
thanks all 🧅
ps i'm on mac m1 don't know if they are compatibility issues
The problem is likely that you are using ruby 3.0.0.
Under Ruby 2.7, I receive the following warning:
warning: calling URI.open via Kernel#open is deprecated, call URI.open directly or use URI#open
And under Ruby 3.0, it has been removed.
So the solution, per the warning:
document = URI.open("https://en.wikipedia.org/wiki/Douglas_Adams").read
I'm trying to require hiredis in irb and it's already sending me an error:
irb(main):001:0> require "hiredis"
WARNING: could not load hiredis extension, using (slower) pure Ruby implementation.
=> true
irb(main):002:0>
Upon further investigation, I notice that it's crashing at this part of the code.
# hiredis-rb/lib/hiredis/connection.rb
module Hiredis
begin
require "hiredis/ext/connection"
Connection = Ext::Connection
rescue LoadError
warn "WARNING: could not load hiredis extension, using (slower) pure Ruby implementation."
require "hiredis/ruby/connection"
Connection = Ruby::Connection
end
end
So, I required the file hiredis/ext/connection and the error I get is the following error:
irb(main):001:0> require "hiredis/ext/connection"
LoadError: /home/***/projects/***/.gemset/extensions/x86_64-linux/2.1.0-static/hiredis-0.5.2/hiredis/ext/hiredis_ext.so:
undefined symbol: redisReaderFree -
/home/***/projects/***/.gemset/extensions/x86_64-linux/2.1.0-static/hiredis-0.5.2/hiredis/ext/hiredis_ext.so
from /home/***/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
I'm using Ubuntu and latest stable version of Redis (2.8.18). How do I fix this? Thanks!
EDIT:
So after looking at the hiredis-rb page: https://github.com/redis/hiredis-rb, it says that I should do the following:
To use hiredis with redis-rb, you need to require
redis/connection/hiredis before creating a new connection.
So I did a require "redis/connection/hiredis" on irb and then require "hiredis" and everything worked fine, no more warnings.
But now the warnings don't happen at all anymore now. I assumed that I'd need to require "redis/connection/hiredis" everytime for it to work but now it just works. So I dunno why it's not warning me anymore now. I thought calling require "redis/connection/hiredis" during that irb session was only for that session, not all succeeding sessions.
We've been running integration tests successfully against Rails 2 using Selenium on both chrome and firefox. However, we've recently upgraded to Rails 3 and are running into issues creating a chrome webdriver instance.
When we attempt to create, we get the following stack:
irb(main):002:0> profile = Selenium::WebDriver::Chrome::Profile.new
translate])#<Selenium::WebDriver::Chrome::Profile:0x64f2fd0 #extensions=[], #model=nil>
irb(main):003:0> profile['download.prompt_for_download'] = false
false
irb(main):004:0> driver = Selenium::WebDriver.for(:chrome, :profile => profile, :switches => %w[--ignore-certificate-errors --disable-popup-blocking --disable-translate])
ArgumentError: wrong number of arguments (0 for 1)
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/platform.rb:157:in `open'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/platform.rb:157:in `ip'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/platform.rb:170:in `interfaces'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/port_prober.rb:23:in `free?'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/port_prober.rb:5:in `above'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/chrome/service.rb:33:in `default_service'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/chrome/bridge.rb:14:in `initialize'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/driver.rb:37:in `new'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/common/driver.rb:37:in `for'
from /var/www/myapp/shared/bundle/ruby/1.8/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver.rb:67:in `for'
from (irb):4
Any tips?
I saw this when I had included a gem which included the "backports" gem as part of its dependencies into my Gemfile. The backports gem rewrites some Ruby 1.8 internals, which overwrote parts of the UDPSocket core class. Try getting rid of the backports gem and giving it a shot.
ChromeDriver Installation:
Download Chromedriver 2.x from "http://chromedriver.storage.googleapis.com/index.html?path=2.8/." Unzip it and save it in a folder on any drive. Set path by following steps :
Copy the path till chromedriver.exe
Right click on Computer and select ‘Properties’
Select ‘Advanced system variables’
Select ‘Environment variables’
Click on Edit button for ‘Path’ variable of ‘User variables’
Append the chromedriver path
Save changes.
Run Selenium Test :
Now run your selenium test. It will run on the chrome browser.
Sample Code
require 'selenium-webdriver'
$driver = Selenium::WebDriver.for :chrome
$driver.navigate.to "https://www.google.co.in/"
$driver.manage().window().maximize()
$driver.quit()
NOTE : You need to install latest chromedriver for latest version of Chrome browser
This was caused by an interference with the backports gem and the fact that the socket library reuses IO.open although it changes the interface.
Upgrading backports to v2.6.7 or above should resolve this.
I am working with the Shopsense Ruby Gem however I am unable to use the gem. Making requests exactly as in the test I receive the following error:
/Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:455:in `block in get_response': undefined method `request_uri' for #<URI::Generic:0x007fd5b3a66810> (NoMethodError)
from /Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:745:in `start'
from /Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:454:in `get_response'
from /Users/rudolph9/.rvm/gems/ruby-1.9.3-p0/gems/Shopsense-0.1.1/lib/Shopsense.rb:76:in `do_search'
from test_shopsense.rb:10:in `<main>'
However, the test works fine if I clone the repository, modify the test and require the source directly as follows:
1 #!/usr/bin/env ruby¬
2 require 'rubygems'¬
3 #require 'Shopsense'¬
4 require '../lib/shopsense.rb'¬
.
.
.
What is the issue when using the gem it self??
Do you have an older version of the gem installed, or another gem which is named Shopsense?
With the error you're getting, I suspect the issue would be related ruby trying to automatically find the gem when you do require 'Shopsense' and finding something other than what you want. When you do require '../lib/shopsense.rb' it defines a specific path to the gem, so you always get the gem you want.
I don't have any experience with Shopsense, but the link you supplied looks like its a version 0.1.0, while the ruby interpreter found a Shopsense-0.1.1. I suspect the issue has to do with that. In fact, the source for Shopsense you linked to, line 76 (where the error is in your output) is a blank line.
I am experiencing issues when I am trying to run my .rb-file with the Ruby-command trying to access a gem. The gem i am trying to use is Ruby-Whois. I have an example script below that when I try to execute it through "ruby whois.rb" I get this error message:
./whois.rb:6: uninitialized constant Whois (NameError)
However, if I run the same script line by line in IRB I get the expected result. What may cause this?
Below is whois.rb
require "rubygems"
require "whois"
domain = "google.com"
c = Whois::Client.new
a = c.query(domain)
puts a
change the name of your file - there is ambiguity in require 'whois' and ruby is requireing your file instead of a gem. when you do it line by line in irb ruby knows what you exactly want to require, so everything works.