Selenium使用PhantomJS

版权声明:本文为 [onefine] 原创文章,转载请注明出处: https://blog.csdn.net/jiduochou963/article/details/88243465

PhantomJS1是一个可编写脚本的无头网页浏览器。它运行在Windows,macOS,Linux和FreeBSD上。

使用QtWebKit作为后端,它为各种Web标准提供快速和本机支持:DOM处理,CSS选择器,JSON,Canvas和SVG。

注意:多进程情况下PhantomJS性能会下降很严重。

到PhantomJS官网 http://phantomjs.org/download.html 下载相应环境的版本。

简单使用:

from selenium import webdriver
# from time import sleep

brower = webdriver.PhantomJS(executable_path='D:/selenium/phantomjs.exe')
brower.get("http://httpbin.org/ip")
print(brower.page_source)
# sleep(10)
brower.quit()

输出:

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 '
<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">{
  "origin": "194.156.230.140, 194.156.230.140"
}
</pre></body></html>

警告说:对PhantomJS的Selenium支持已被弃用,请使用无界面的Chrome或Firefox。


参考:
如何在使用 RemoteWebDriver 打开网页的同时获取 Http 状态码 https://www.cnblogs.com/lexfu/p/5288299.html
Selenium+PhantomJS使用时报错原因及解决方案 https://blog.csdn.net/u010358168/article/details/79749149


  1. http://phantomjs.org/ , 此项目已停止维护。 ↩︎

猜你喜欢

转载自blog.csdn.net/jiduochou963/article/details/88243465