简体   繁体   English

Wat与Tor浏览器

[英]Watir with Tor browser

I've been playing with Watir and Tor browser and I can't get them to work. 我一直在使用Watir和Tor浏览器,但无法使用它们。 The correct browser opens, however, I'm unable to open a website. 正确的浏览器打开,但是,我无法打开网站。

My code: 我的代码:

Selenium::WebDriver::Firefox.path = '\path\Tor Browser\Start Tor Browser.exe'
driver = Selenium::WebDriver.for :firefox
browser = Watir::Browser.new :firefox, :driver => driver

This results in a message box popping up, which says: 这将导致弹出一个消息框,其中显示:

Your Firefox profile cannot be loaded. 您的Firefox配置文件无法加载。 It may be missing or inaccessible. 它可能丢失或无法访问。

The correct browser also opens up, however, the website doesn't. 正确的浏览器也会打开,但是网站没有打开。

I've also tried: 我也尝试过:

Selenium::WebDriver::Firefox.path = '\path\Tor Browser\Browser\firefox.exe'
driver = Selenium::WebDriver.for :firefox
browser = Watir::Browser.new :firefox, :driver => driver

With this, the message box doesn't appear, but still, the website is not loaded. 这样,不会出现消息框,但仍未加载网站。

I'm not sure, if the problem is in my code or in the browser. 我不确定问题是否出在我的代码或浏览器中。 Thank you very much for any help! 非常感谢您的帮助!

Start Tor then run this, assuming your socks port is 9050 假设您的袜子端口为9050,请启动Tor,然后运行此命令

require 'watir-webdriver'

profile = Selenium::WebDriver::Firefox::Profile.new
profile['network.proxy.socks'] = "127.0.0.1"
profile['network.proxy.socks_port'] = 9050
profile['network.proxy.type'] = 1
$browser = Watir::Browser.new :firefox, :profile => profile

$browser.goto "whatsmyip.org" 

Firefox and Tor are not the same browser. Firefox和Tor不是同一浏览器。 Watir uses webdriver API to control the browser. Watir使用Webdriver API来控制浏览器。 You can't use Firefox webdriver API to control another browser. 您不能使用Firefox WebDriver API来控制其他浏览器。

In your second example, browser don't open the site, but you don't tell him to. 在第二个示例中,浏览器不会打开该站点,但是您不会告诉他这样做。 You should add : 您应该添加:

browser.goto('http://my.example.com')

And don't forget to put a browser.quit at the end of your code to close the browser. 并且不要忘记在代码末尾放置一个browser.quit来关闭浏览器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM