I am trying to use Selenium with Firefox to scarpe a Cloudflare protect web page. I am having issue when using with TOR, although i get a new ip address but it throws an error when I am trying to launch firefox. My code is as below :

import time
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys

from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.proxy import Proxy, ProxyType

import psutil, signal, os
import string
import socket
import socks
import requests
from stem import Signal
from stem.control import Controller
import json
import urllib3
import logging

# Import Select class
from selenium.webdriver.support.ui import Select
import sys

url = ""
controller = Controller.from_port(port=9051)

def init(args):
    ''' store the counter for later use '''
    global counter
    counter = args

def connectTor():
    socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5 , url, 9050, True)
    socket.socket = socks.socksocket
def renew_tor():
    #print("Renewing:" + str(pname))
def showmyip():
    r = requests.get('http://httpbin.org/ip')
    ip_address = r.text.strip()

 #Connect TOR

profile = FirefoxProfile('/home/sg2/.mozilla/firefox/xbbstpn2.default')
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', '')
profile.set_preference('network.proxy.socks_port', 9051)
profile.set_preference("network.proxy.socks_version", 5)

# browser = webdriver.Firefox(firefox_profile=profile)

browser = webdriver.Firefox(firefox_profile= profile, executable_path="/usr/local/bin/geckodriver", log_path="/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/geckodriver.log")

Please guide me.

New contributor
DaVinci007 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

DaVinci007 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.