报错:AttributeError: module 'selenium.webdriver' has no attribute 'Chrome'

脚本开头部分:

# coding = utf-8

import time
from selenium import webdriver

option = webdriver.ChromeOptions()
option.add_argument('disable-infobars')

driver = webdriver.Chrome(chrome_options = option)
driver.maximize_window()
driver.get("https://www.baidu.com")
time.sleep(2)
……

……

问题描述:在sublime中能够正常执行,在PyCharm中则一直提示:AttributeError: module 'selenium.webdriver' has no attribute XXXX

解决方法:

尝试:考虑到在sublime中执行的脚本所在路径,有 chromedriver; 然后把chromedriver copy 到PyCharm中的脚本所在路径,并在PyCharm中安装i,安装完成后,运行,提示:

          raise RuntimeError('This package supports only Linux, MacOSX or Windows platforms')
RuntimeError: This package supports only Linux, MacOSX or Windows platforms

失败;

尝试:给Chrome浏览器配置 chromedriver,同时改了脚本名称,注释其中几行,运行脚本,失败

import time

# import chromedriver as chromedriver
from selenium import webdriver

class BaiduSearch(object):
# option = webdriver.ChromeOptions()
# option.add_argument('disable-infobars')

driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(10)
提示: AttributeError: module 'selenium.webdriver' has no attribute 'Chrome'

尝试: 添加外部库,在pycharm-setting-project Interpreter中手动添加了selenium。添加成功后,代码没有改动,再重启pycharm,运行,通过。

 

posted @   Cranberries  阅读(30427)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示