2

I want to know how to use selenium. to scrape dynamic page. Is there some relation to installing Firefox?

from selenium import webdriver
driver=webdriver.Firefox()

selenium.common.exceptions.WebDriverException: Message: Failed to find firefox binary. You can set it by specifying the path to 'firefox_binary':

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('/path/to/binary')
driver = webdriver.Firefox(firefox_binary=binary)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • [Check this tutorial](https://www.guru99.com/selenium-python.html). And yes, you will need the Browser that you intend to use. Because the Selenium only controls it – D.Kastier Apr 15 '19 at 16:17
  • I use edge so I changed to "driver = webdriver.Edge(executable_path='C:\MicrosoftWebDriver.exe') " but "os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'MicrosoftWebDriver.exe' executable needs to be in PATH. Please download from http://go.microsoft.com/fwlink/?LinkId=619687" –  Apr 15 '19 at 17:34
  • @AtsushiSakata Please don't change the question once you have received well researched answers else the working answers will become invalid and won't be useful to future readers. If your requirement have changed feel free to raise a new question as per your new requirement. Stack Overflow contributors will be happy to help you out. As of now I have reverted the question to it's original state. – undetected Selenium Apr 16 '19 at 14:08

1 Answers1

1

This error message...

selenium.common.exceptions.WebDriverException: Message: Failed to find firefox binary. You can set it by specifying the path to 'firefox_binary':

...implies that the GeckoDriver was unable to find the firefox binary.

Perhaps Firefox browser is installed in a non-conventional location on your machine so GeckoDriver is unable to find it.


Solution

Incase Firefox is installed in a non-conventional location on your machine you need to pass the absolute location of the firefox binary as follows:

from selenium import webdriver

binary = '/path/to/firefox'
# Example of using Firefox Developer Edition on Windows OS
# binary = r'C:\Program Files\Firefox Developer Edition\firefox.exe'
# Example of using Firefox Nightly Edition on Windows OS
# binary = r'C:\Program Files\Nightly\firefox.exe'

options = webdriver.FirefoxOptions()
options.binary = binary
browser = webdriver.Firefox(firefox_options=options, executable_path='/path/to/geckodriver')
browser.get('http://google.com/')
browser.quit()

You can find a relevant discussion in How to open Firefox Developer Edition through Selenium

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • but this error os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. –  Apr 16 '19 at 12:21
  • Provide the _absolute path_ of **GeckoDriver** in place of `/path/to/geckodriver`. You already know where you have downloaded and extracted it. – undetected Selenium Apr 16 '19 at 12:23
  • then this Message: Unable to find a matching set of capabilities –  Apr 16 '19 at 12:36
  • There is a mismatch in the _GeckoDriver_, _Firefox_ and _Selenium_ versions. See: [selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities with GeckoDriver, Selenium and Firefox](https://stackoverflow.com/questions/52002958/selenium-common-exceptions-sessionnotcreatedexception-message-unable-to-find-a/52006033#52006033) – undetected Selenium Apr 16 '19 at 12:39
  • but still caps I changed the content –  Apr 16 '19 at 14:01
  • If your requirement have changed feel free to raise a new question as per your new requirement. Stack Overflow contributors will be happy to help you out. – undetected Selenium Apr 16 '19 at 14:12