[英]Watir with Tor browser
我一直在使用Watir和Tor瀏覽器,但無法使用它們。 正確的瀏覽器打開,但是,我無法打開網站。
我的代碼:
Selenium::WebDriver::Firefox.path = '\path\Tor Browser\Start Tor Browser.exe'
driver = Selenium::WebDriver.for :firefox
browser = Watir::Browser.new :firefox, :driver => driver
這將導致彈出一個消息框,其中顯示:
您的Firefox配置文件無法加載。 它可能丟失或無法訪問。
正確的瀏覽器也會打開,但是網站沒有打開。
我也嘗試過:
Selenium::WebDriver::Firefox.path = '\path\Tor Browser\Browser\firefox.exe'
driver = Selenium::WebDriver.for :firefox
browser = Watir::Browser.new :firefox, :driver => driver
這樣,不會出現消息框,但仍未加載網站。
我不確定問題是否出在我的代碼或瀏覽器中。 非常感謝您的幫助!
假設您的襪子端口為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和Tor不是同一瀏覽器。 Watir使用Webdriver API來控制瀏覽器。 您不能使用Firefox WebDriver API來控制其他瀏覽器。
在第二個示例中,瀏覽器不會打開該站點,但是您不會告訴他這樣做。 您應該添加:
browser.goto('http://my.example.com')
並且不要忘記在代碼末尾放置一個browser.quit
來關閉瀏覽器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.