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()
5
  • Try adding a full path of the geckodriver executable in your PATH environment variable. Commented Nov 28, 2016 at 5:38
  • Please make sure that geckodriver is added in PATH. And restart the IDE. Commented Nov 28, 2016 at 6: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- stackoverflow.com/questions/40834238/… Commented Nov 28, 2016 at 6:36
  • Possible duplicate of Selenium using Python - Geckodriver executable needs to be in PATH Commented Feb 6, 2017 at 11:42
  • Check my answer here : stackoverflow.com/a/42478941/5986816 Commented Feb 28, 2017 at 10:10

1 Answer 1

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):

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

Comments

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.