1

I'm having problems with the following python script on this line:

driver = webdriver.Firefox(firefox_profile=profile, proxy=proxy). 

I am getting this error:

Traceback (most recent call last): File "C:\Python27\example2.py", line 45, in driver = webdriver.Firefox(firefox_profile=profile, proxy=proxy) File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in init self.service.start() File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start os.path.basename(self.path), self.start_error_message) WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

I have looked for documentation on what could be causing the problem but I haven't been able to find anything that would resolve this issue. Any thoughts?

Also, is there a way that I can use IE instead of Firefox and if so what code do I need to switch out with what?

Following is the full code:

import random, time, requests
from selenium import webdriver
from selenium.webdriver.common.proxy import *
from bs4 import BeautifulSoup

USER_AGENTS_FILE = './user_agents.txt'
RUNNING = True

def LoadUserAgents(uafile=USER_AGENTS_FILE) :
uas = []
with open(uafile, 'rb') as uaf:
    for ua in uaf.readlines():
        if ua:
            uas.append(ua.strip()[1:-1-1])
random.shuffle(uas)
return uas

uas = LoadUserAgents()

while RUNNING == True:
address = []

response = requests.get('https://www.sslproxies.org')
soup = BeautifulSoup (response.content, "html.parser")

rows = soup.findAll ("tr")

for row in rows:
    if (len(row.findAll("td"))== 8):
        address.append(row.contents[0].contents[0] + ':' + row.contents[1].contents[0])

random.shuffle(address)

PROXY = random.choice(address)
proxy = Proxy ({
    'proxyType': ProxyType.MANUAL,
    'httpProxy': PROXY,
    'ftpProxy': PROXY,
    'sslProxy': PROXY,
    'noProxy': ''
    })

profile = webdriver.FirefoxProfile()
profile.set_preference('general.useragent.override', random.choice(uas))
driver = webdriver.Firefox(firefox_profile=profile, proxy=proxy)
driver.set_page_load_timeout(10)
try:
    driver.get("http://www.ipchicken.com/")
    time.sleep(60)
    driver.quit()
except:
    diver.quit()
captainsac
  • 2,484
  • 3
  • 27
  • 48
ClydeHopper
  • 11
  • 1
  • 2
  • 6
  • Try adding a full path of the geckodriver executable in your PATH environment variable. – Eddie Nov 28 '16 at 05:38
  • Please make sure that geckodriver is added in PATH. And restart the IDE. – Prabhakar Nov 28 '16 at 06:30
  • Have you tried running the most simple selenium webdriver program? Is it working well? It seems to me that even simple code, won't work in your case. Try to follow instruction from my reply here- http://stackoverflow.com/questions/40834238/how-to-properly-setup-windows7-to-use-selenium-with-firefox-tdd-with-python/40837887#40837887 – Shoaib Akhtar Nov 28 '16 at 06:36
  • Possible duplicate of [Selenium using Python - Geckodriver executable needs to be in PATH](http://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path) – Chanda Korat Feb 06 '17 at 11:42
  • Check my answer here : http://stackoverflow.com/a/42478941/5986816 – Ahmad Taha Feb 28 '17 at 10:10

1 Answers1

0

To use different browsers, you will only need to download the driver executable and then add it to your path. Calling the browser is quite simple:

from selenium import webdriver
# ie
ie_driver = webdriver.Ie()
# chrome
chrome_driver = webdriver.Chrome()
# etc ..

Common browser drivers (complete list):

Corey Goldberg
  • 59,062
  • 28
  • 129
  • 143
cacti5
  • 2,006
  • 2
  • 25
  • 33