怎么下载旧版本的Selenium

本文介绍如何解决Selenium配合PhantomJS时出现的警告信息,通过安装旧版本的Selenium来避免使用已弃用的PhantomJS浏览器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

试运行一个爬虫:

from bs4 import BeautifulSoup
from selenium import webdriver
import urllib
driver = webdriver.PhantomJS(
executable_path='/usr/local/bin/phantomjs') # 浏览器的地址 如果是windows,应该是某个exe地址
def search(keyword):
url_keyword = urllib.parse.quote(keyword)
url = "http://www.tianyancha.com/search/" + url_keyword + "?checkFrom=searchBox"
print(url)
driver.get(url)
bsObj = BeautifulSoup(driver.page_source, "html5lib")
print(bsObj)
company_list = bsObj.find_all("span", attrs={"ng-bind-html": "node.name | trustHtml"})
for company in company_list:
print(company.get_text())
if name == 'main':
search("阿里巴巴 马云")

结果第二行就告诉我:
UserWarning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead
warnings.warn('Selenium support for PhantomJS has been deprecated, please use headless '

这 不 能 忍!

赶紧下载旧版本的Selenium
在命令行运行:

pip install selenium==2.33

参考链接:
https://www.jianshu.com/p/df5f141de455

https://pypi.python.org/pypi/selenium/2.42.1

http://www.yuqiaochuang.com/article/?article_id=33&category=Python教程

转载于:https://www.cnblogs.com/hxypqr/p/8468641.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值