Python Forum

Full Version: selenium error :
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello all ...
im trying to use selenium i keep getting this error :

Error:
Traceback (most recent call last): File "c:/Users/root/Desktop/token.py", line 3, in <module> browser = webdriver.Firefox(executable_path=r"C:\Users\root\Desktop\geckodriver.exe") File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__ self.service.start() File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 95, in start (os.path.basename(self.path), self.start_error_message, str(e))) selenium.common.exceptions.WebDriverException: Message: The executable geckodriver.exe needs to be available in the path. 'module' object has no attribute 'system'
my code :
from selenium import webdriver

browser = webdriver.Firefox(executable_path=r"C:\Users\root\Desktop\geckodriver.exe")
browser.get('http://www.google.com')
when i run the code for the second time the error is :

Error:
Traceback (most recent call last): File "c:/Users/root/Desktop/token.py", line 1, in <module> from selenium import webdriver File "C:\Python27\lib\site-packages\selenium\webdriver\__init__.py", line 18, in <module> from .firefox.webdriver import WebDriver as Firefox # noqa File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 29, in <module> from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 27, in <module> from .remote_connection import RemoteConnection File "C:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 20, in <module> import platform File "c:\Users\root\Desktop\platform.py", line 4, in <module> os.makedirs(d+"/test") File "C:\Python27\lib\os.py", line 157, in makedirs mkdir(name, mode) WindowsError: [Error 183] Cannot create a file when that file already exists: 'C:\\Users\\root\\AppData\\Roaming/test'
see: https://python-forum.io/Thread-Web-scraping-part-2

search for 'Headless(not loading browser):'

make sure you add options to your code.
(Nov-11-2018, 09:46 AM)Larz60+ Wrote: [ -> ]see: https://python-forum.io/Thread-Web-scraping-part-2

search for 'Headless(not loading browser):'

make sure you add options to your code.

this is my new code :
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import time
 
#--| Setup
options = Options()
options.set_headless(headless=True)
caps = webdriver.DesiredCapabilities().FIREFOX
caps["marionette"] = True
browser = webdriver.Firefox(firefox_options=options, capabilities=caps, executable_path=r"C:\Users\root\Desktop\geckodriver.exe")
#--| Parse
browser.get('https://www.python.org/')
time.sleep(2)
t = browser.find_element_by_xpath('//*[@id="dive-into-python"]/ul[2]/li[1]/div[1]/pre/code/span[1]')
print(t.text)
browser.quit()
and this is the new error :

Error:
Traceback (most recent call last): File "c:/Users/root/Desktop/token.py", line 10, in <module> browser = webdriver.Firefox(firefox_options=options, capabilities=caps, executable_path=r"C:\Users\root\Desktop\geckodriver.exe") File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__ self.service.start() File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 95, in start (os.path.basename(self.path), self.start_error_message, str(e))) selenium.common.exceptions.WebDriverException: Message: The executable geckodriver.exe needs to be available in the path. 'module' object has no attribute 'system'
is this the right path for geckodriver? C:\Users\root\Desktop\geckodriver.exe"
(Nov-11-2018, 10:36 AM)Larz60+ Wrote: [ -> ]is this the right path for geckodriver? C:\Users\root\Desktop\geckodriver.exe"

yes
(Nov-11-2018, 10:28 AM)evilcode1 Wrote: [ -> ]The executable geckodriver.exe needs to be available in the Path.
The mean Windows Environment Variables Path
So you look what's folder that's in Path and place geckodriver.exe there,
or you can add own folder to Path(Restart) eg C:\web_drivers.
(Nov-11-2018, 11:29 AM)snippsat Wrote: [ -> ]
(Nov-11-2018, 10:28 AM)evilcode1 Wrote: [ -> ]The executable geckodriver.exe needs to be available in the Path.
The mean Windows Environment Variables Path
So you look what's folder that's in Path and place geckodriver.exe there,
or you can add own folder to Path(Restart) eg C:\web_drivers.
still nor work still the same last error
(Nov-12-2018, 10:43 AM)evilcode1 Wrote: [ -> ]still nor work still the same last error
If have trouble with Path setup,just have geckodriver.exe in same folder as Scripts you run.
E:\div_code\scrape
|-- duck_go.py
|-- geckodriver.exe
# duck_go.py
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys
import time

#--| Setup
options = Options()
#options.add_argument("--headless")
caps = webdriver.DesiredCapabilities().FIREFOX
caps["marionette"] = True
browser = webdriver.Firefox(firefox_options=options, capabilities=caps, executable_path=r"geckodriver.exe")
#--| Parse or automation
browser.get('https://duckduckgo.com')
input_field = browser.find_elements_by_css_selector('#search_form_input_homepage')
input_field[0].send_keys('car' + Keys.RETURN)
time.sleep(3)
images_link = browser.find_elements_by_link_text('Images') #Or your country name of images
images_link[0].click()
time.sleep(5)
browser.quit()