python - Python 中的 selenium 问题(可能安装 chrome webdriver)
问题描述
我想我已经正确安装了 chrome 网络驱动程序,虽然这可能是问题,但是当我运行命令提示符并键入“chromedriver”时它会运行,但是当我进入 sublime 并尝试去谷歌并打印标题和 URL为了验证事情是否正常,我收到了这个错误
我不太确定这意味着什么或它想对我说什么
我正在运行的代码
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com")
print(driver.title)
print(driver.current_url)
我得到的错误
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]
解决方案
您遇到的问题如下:
- 你进口
webdriver
- 导入触发了
email.parser
我们在错误中看到的导入
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
- python 解释器在其路径中查找名为
email
. - 它找到了一个模块,但它不是它要查找的模块,而是您自己的模块,正如我们在错误中看到的那样
File "C:\Users\Coding\Desktop\python\email.py", line 8, in <module>
loop (
- 正如我们所见,该模块是在以下位置找到的,
C:\Users\Coding\Desktop\python\email.py
而且正如我所怀疑的,这不是解释器正在搜索的实际模块的路径。
推荐阅读
- batch-file - 用户输入批处理文件崩溃@echo var
- docker - 如何为 docker 安装 wkhtmltopdf
- python - 如何在特定的欧拉角范围内随机绘制四元数进行旋转?
- discord.js - Discord.js 机器人没有获取带有 args 名称的图像
- c++ - C ++中的openCV Mat访问冲突
- scala - flink什么相当于scala api中的parseQuotedStrings
- php - 如何排除父 Xpath 类中的类?PHP
- python - PIL 和 Pillow 安装程序在未安装的情况下突然关闭 (Windows 10)
- php - 更好地使用 Wordpress 主题 Mod
- php - Array_push 不生成新键,而是替换当前值