已解决(最新版selenium报错)AttributeError: module ‘selenium.webdriver‘ has no attribute ‘PhantomJS‘

已解决(最新版selenium报错)AttributeError: module ‘selenium.webdriver‘ has no attribute ‘PhantomJS‘







报错信息


我的代码

from selenium import webdriver

browser = webdriver.PhantomJS()

# 发送请求
browser.get('https://www.baidu.com/')

# 打印页面的标题
print(browser.title)

# 退出模拟浏览器
browser.quit()  # 一定要退出!不退出会有残留进程

报错信息

Traceback (most recent call last):
  File "E:/Python学习/1.py", line 3, in <module>
    browser = webdriver.PhantomJS()
AttributeError: module 'selenium.webdriver' has no attribute 'PhantomJS'

在这里插入图片描述



报错翻译


报错翻译:AttributeError:模块“selenium”。“webdriver”没有属性“PhantomJS”



报错原因


报错原因:新版的 selenium已经放弃PhantomJS,所以才会出现module ‘selenium.webdriver’ has no attribute ‘PhantomJS’。PhantomJS安装都是最新版本,pip install selenium安装的也是最新版本。



解决方法


1. 先把selenium卸载,代码如下:

pip uninstall selenium

2.安装selenium==2.48.0版本的,代码如下:

pip install selenium==2.48.0

具体操作截图:


在这里插入图片描述


3. 再次运行成功:


在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/yuan2019035055/article/details/125830305