0

I am trying to run python selenium (firefox driver) with tor. I checked this link (Using Selenium WebDriver with Tor) but this is the java implementation. I am relatively new to selenium and I encounter problems in translate the java code to the Python API.

Someone encounter this issue before?

3
  • I have not encountered an issue. Selenium works great with Python and Tor. Commented May 30, 2015 at 1:41
  • 1
    Can you please show a simple example? Thanks for the replay! Commented May 31, 2015 at 5:39
  • ok ok. I'll post it as an answer in a little while. Please accept it when you get a chance. Commented May 31, 2015 at 16:40

1 Answer 1

1

Here is the code that works for me in Python 2.7 (I last updated it on March 12, 2015). As an added bonus, it fills in the username and password field on agora and asks you to fill in captcha that you see then clicks the submit button. You need to create a default firefox profile that has it's proxy set to tor (127.0.0.1:9050) and fill the path to that profile name into the startbrowser function profiler variable:

from selenium import webdriver 
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.common.exceptions import NoSuchFrameException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

username = 'agora username'
password = 'agora password'
def go_to_page(br):
    #page_num = page_num - 1
    #start_results = page_num * 100
    #start_results = str(start_results)
    url = 'http://agorahooawayyfoe.onion'
    print '[*] loading url: '+url
    br.get(url)
    #br.get_screenshot_as_file('agora.tiff')
    usernamed = br.find_element_by_name("username")
    usernamed.send_keys(username) # password
    passwordd = br.find_element_by_name("password") # enterCaptcha
    passwordd.send_keys(password)
    captchad = br.find_element_by_name("enterCaptcha")
    capt = raw_input('enter captcha you see on screen: ')
    captchad.send_keys(capt)
    br.implicitly_wait(3)
    br.find_element_by_name("submit").click()

def start_browser():
    profiler = webdriver.FirefoxProfile('/Users/your username/Library/Application Support/Firefox/Profiles/vxh0qxtt.tor')
    br = webdriver.Firefox(firefox_profile=profiler)
    br.implicitly_wait(10)
    return br

def main():
    br = start_browser()
    go_to_page(br)

main()
Sign up to request clarification or add additional context in comments.

3 Comments

Hi thanks for the code it helped me allot!. I didn't used the profile correctly. Thanks for the help!!!! For me I needed to change the port to 9150.
@dubin awesome glad to hear
I got this error PermissionError: [WinError 5] Access is denied

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.