from bs4 import BeautifulSoup, SoupStrainer
from selenium import webdriver
from selenium.webdriver import chrome
from selenium.webdriver.chrome.options import Options
url = 'https://...'
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument("--headless")
driver = webdriver.Chrome('path')
driver.get(url)
Error:
Traceback (most recent call last):
File "", line 20, in <module>
driver.get(EPL_url)
File "", line 333, in get
self.execute(Command.GET, {'EPL_url': url})
File "", line 321, in execute
self.error_handler.check_response(response)
File "", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown command: unknown command: session/9df33bd6f0e57084300c81738cf6c2d5/EPL_url
I have tried to look at all the potential errors around this and have found nothing. The annoying things is, the "driver.get()" function was working perfectly earlier. It only seemed to have been disrupted after I had changed the variable name of the URL. I seriously do not know what to do and need to get this code back up and running.
Please help me with the above error so I can rectify this!! It would be much appreciated.
This issue can be because of the path of the chrome driver.
Here's a simpler solution: install the python-chrome drive package, import it in your script, and it's done.
Step by step:
pip install chromedriver-binary
import the package
from selenium import webdriver
import chromedriver_binary # Adds chromedriver binary to path
driver = webdriver.Chrome()
driver.get("http://www.python.org")
Reference: https://pypi.org/project/chromedriver-binary/
Related
I have properly install selenium and chromedriver and wanted to execute this below code at python
import selenium
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r"C:\Users\SM.Nibir\Desktop\Python\chromedriver_win32\chromedriver.exe")
but I am getting these errors on my output panel
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/SM. Nibir/Desktop/Python/import os.py", line 3, in <module>
driver = webdriver.Chrome()
File "C:\python\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\python\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Who can I solve this problem and make this code work properly?
first of all, your first mistake is that you wrote "import selenium from.."
so the order has to be that way:
from selenium import webdriver
driver=webdriver.Chrome(executable_path=r"C:\Users\...chromedriver.exe")
ofcourse that you need to change the path for the correct location of your chromedriver.exe file.
let me know if it helps.
I'm trying to run a Python script in a CentOS server. However, I've been unable to install Google Chrome (I've read it is no longer supported by CentOS) so I decided to try with Firefox. However, I get the following error when trying to run it with Firefox.
Traceback (most recent call last):
File "/home/uscomplianceserv/public_html/scrapdata/FMCSAScraper.py", line 73, in <module>
init_selenium()
File "/home/uscomplianceserv/public_html/scrapdata/FMCSAScraper.py", line 40, in init_selenium
webdriver.Firefox(firefox_options = options, executable_path='/home/uscomplianceserv/public_html/scrapdata/geckodriver')
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 133, in __init__
if options.binary is not None:
AttributeError: 'Options' object has no attribute 'binary'
This is what I'm using:
Centos 6.10
Python 2.7
Selenium 3.14.0
Firefox 45
Geckodriver v0.21.0
This is the selenium webdriver initialization function:
def init_selenium():
global driver, page
options = Options()
options.add_argument("-headless")
driver = webdriver.Firefox(firefox_options = options, executable_path='/home/uscomplianceserv/public_html/scrapdata/geckodriver')
driver.get(url)
I am running python 2.7.12 with selenium version 2.53.6 and firefox 46.0.1 on an AWS Ubuntu Server 16.04 LTS instance. I've installed pyvirtualdisplay.
When I run this code:
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(1024, 768))
display.start()
driver = webdriver.Firefox()
I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/anaconda2/lib/python2.7/site- packages/selenium/webdriver/firefox/webdriver.py", line 55, in __init__
self.binary = firefox_binary or capabilities.get("binary", FirefoxBinary())
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 47, in __init__
self._start_cmd = self._get_firefox_start_cmd()
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 163, in _get_firefox_start_cmd
" Please specify the firefox binary location or install firefox")
RuntimeError: Could not find firefox in your system PATH. Please specify the firefox binary location or install firefox
I've tried to add a link to my bash profile
echo export 'PATH="$PATH:/home/firefox"' >> ~/.bashrc
But have not been successful. Any help would be greatly appreciated.
After Running the below Command:
from selenium import webdriver
I get the Following error:
Traceback (most recent call last):
File "C:\Users\tempjatop\workspace\TestPython\Sample.py", line 1, in <module>
from selenium import webdriver
File "C:\Python\lib\site-packages\selenium-3.0.0b2-py3.5.egg\selenium\webdriver\__init__.py", line 25, in <module>
from .safari.webdriver import WebDriver as Safari # noqa
File "C:\Python\lib\site-packages\selenium-3.0.0b2-py3.5.egg\selenium\webdriver\safari\webdriver.py", line 49
executable_path = os.environ.get("SELENIUM_SERVER_JAR")
^
TabError: inconsistent use of tabs and spaces in indentation
I don't know why it is redirecting it to safari webdriver.
Please suggest any fixes or am i doing anything wrong?
As the error says:
TabError: inconsistent use of tabs and spaces in indentation
Check for indentations in your code and correct the inconsistent ones.
I'm creating a python script with selenium webdriver. I need to use an extension in firefox, but when I test with a little script, the script produces an error like this:
Traceback (most recent call last):
File "C:\Users\User\Desktop\Bot\Mania.py", line 8, in <module>
firefoxProfile.add_extension(elem)
File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\firefox_profile.py", line 93, in add_extension
self._install_extension(extension)
File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\firefox_profile.py", line 264, in _install_extension
with open(os.path.join(tmpdir, name), 'wb') as f:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\User\\AppData\\Local\\Temp\\tmpzq3rmztk.firebug-2.0.11-fx.xpi\\content/firebug/'
[Finished in 0.4s with exit code 1]
The sample code is it:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import os
firefoxProfile = FirefoxProfile()
elem = "quickjava-2.0.6-fx.xpi"
firefoxProfile.add_extension(elem)
firefoxProfile.set_preference("thatoneguydotnet.QuickJava.startupStatus.CSS", 2)
driver = webdriver.Firefox(firefoxProfile)
driver.get('http://www.google.cl')
PS: The add-on is in the same folder that the script. I tested with full path but it doesn't work too.
You need to provide an absolute path to the extension:
firefoxProfile.add_extension("/absolute/path/to/the/extension")