简体   繁体   中英

Issues with selenium in Python (Maybe installing chrome webdriver)

I think I've installed chrome web driver correctly although it may be the issue, but when i run command prompt and type "chromedriver" it runs, but when i go into sublime and just try to go to google and print the title and URL to verify that things are working i get this error

I am not really sure what it means or what it is trying to say to me

The code I'm running

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com")
print(driver.title)
print(driver.current_url)

The Error I'm getting

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 900, in _find_spec
AttributeError: '_SixMetaPathImporter' object has no attribute 'find_spec'

During handling of the above exception, another exception occurred:

        Traceback (most recent call last):
  File "C:\Users\Coding\Desktop\python\selenium testing.py", line 1, in <module>
    from selenium import webdriver
  File "C:\Users\Coding\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\selenium\webdriver\__init__.py", line 18, in <module>
    from .firefox.webdriver import WebDriver as Firefox  # noqa
  File "C:\Users\Coding\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\selenium\webdriver\firefox\webdriver.py", line 29, in <module>
    from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
  File "C:\Users\Coding\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\selenium\webdriver\remote\webdriver.py", line 27, in <module>
    from .remote_connection import RemoteConnection
  File "C:\Users\Coding\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\selenium\webdriver\remote\remote_connection.py", line 24, in <module>
    import urllib3
  File "C:\Users\Coding\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\urllib3\__init__.py", line 7, in <module>
    from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
  File "C:\Users\Coding\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\urllib3\connectionpool.py", line 11, in <module>
    from .exceptions import (
  File "C:\Users\Coding\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\urllib3\exceptions.py", line 2, in <module>
    from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 963, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 902, in _find_spec
  File "<frozen importlib._bootstrap>", line 879, in _find_spec_legacy
  File "<frozen importlib._bootstrap>", line 449, in spec_from_loader
  File "C:\Users\Coding\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\urllib3\packages\six.py", line 212, in is_package
    return hasattr(self.__get_module(fullname), "__path__")
  File "C:\Users\Coding\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\urllib3\packages\six.py", line 116, in __getattr__
    _module = self._resolve()
  File "C:\Users\Coding\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\urllib3\packages\six.py", line 113, in _resolve
    return _import_module(self.mod)
  File "C:\Users\Coding\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\urllib3\packages\six.py", line 82, in _import_module
    __import__(name)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 71, in <module>
    import email.parser
  File "C:\Users\Coding\Desktop\python\email.py", line 8, in <module>
    loop (
NameError: name 'loop' is not defined
[Finished in 0.2s]

The Problem you are having is the following:

  • You import webdriver
  • The import triggers the import of email.parser as we see in the error
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 71, in <module>
    import email.parser
  • the python interpreter looks in its path for a module called email .
  • It found a module, but its not the one it was looking for, but your very own module, as we see in the error
File "C:\Users\Coding\Desktop\python\email.py", line 8, in <module>
    loop (
  • As we can see, the module was found at C:\\Users\\Coding\\Desktop\\python\\email.py and, as I suspected, this is not the path of the actual module the interpreter was searching for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM