在Ruby中打开默认浏览器
时间:2020-03-06 14:55:06 来源:igfitidea点击:
在Python中,我们可以执行以下操作:
import webbrowser webbrowser.open_new("http://example.com/")
它将在默认浏览器中打开传入的网址
有红宝石吗?
解决方案
仅Windows解决方案:
require 'win32ole' shell = WIN32OLE.new('Shell.Application') shell.ShellExecute(...)
在MSDN上执行Shell
如果是Windows且是IE,请尝试以下操作:http://rubyonwindows.blogspot.com/search/label/watir还要查看Selenium ruby:http://selenium.rubyforge.org/getting-started.html
高温超导
仅限Mac的解决方案:
system("open", "http://stackoverflow.com/")
或者
`open http://stackoverflow.com/`
跨平台解决方案
首先,安装Launchy gem:
$ gem install launchy
然后,我们可以运行以下命令:
require 'launchy' Launchy.open("http://stackoverflow.com")
这也适用:
system("start #{link}")
最简单的Win解决方案:
`start http://www.example.com`