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