【发布时间】:2018-10-29 04:52:32
【问题描述】:
我的代码是:
from selenium import webdriver
driver = webdriver.PhantomJS(executable_path='driver/bin/phantomjs.exe')
driver.get("https://www.test.com")
print(driver.current_url)
它似乎运行良好,但在它运行之前我总是得到这个错误:
UserWarning: Selenium 对 PhantomJS 的支持已被弃用,请使用无头版本的 Chrome 或 Firefox 代替 warnings.warn('Selenium 对 PhantomJS 的支持已被弃用,请使用无头版本
为什么会出现此错误?我以为我的 PhantomJS 是无头的,因为它仍然可以工作并且没有浏览器弹出窗口,这个错误保存可以忽略吗?
【问题讨论】:
-
PhantomJS 基于旧版本的 webkit,不再维护。 groups.google.com/forum/#!topic/phantomjs/9aI5d-LDuNE
-
好吧,@generalhenry 有没有一种简单的方法可以让 Chrome 或 Firefox 无头?
-
intoli.com/blog/running-selenium-with-headless-chrome short version install chrome, chromedriver 然后在你的代码调用
driver = webdriver.Chrome . . .和你的代码的其余部分应该正常运行。 -
或stackoverflow.com/questions/46753393/… for firefox
-
但 PhontomJS 仍然更快,并且需要大型 carawling 项目。