程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python error reporting series (14) -- selenium support for phantom JS has been deprecated

編輯:Python

List of articles

List of articles

  • List of articles
  • Preface
  • One 、Selenium support for PhantomJS has been deprecated
  • Two 、 Cause analysis
    • 1.selenium Has given up PhantomJS, 了 , It is recommended to use Firefox or Google no interface browser
    • 2. Solution
    • 3. Reference resources
  • summary


Preface

One 、Selenium support for PhantomJS has been deprecated

E:\py\python3.7\Python37\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py:49: 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 '

translate : User warning :Selenium Yes PhantomJS The support of has been abandoned , Please use the headless version of Chrome or Firefox Instead of
Warning .“Selenium Yes PhantomJS The support of has been abandoned , Please use headless”

Two 、 Cause analysis

1.selenium Has given up PhantomJS, 了 , It is recommended to use Firefox or Google no interface browser

PS E:\py\python3.7\test2\test43> python3 -m pip show selenium
WARNING: Ignoring invalid distribution -ip (e:\py\python3.7\python37\lib\site-packages)
Name: selenium nlmZwRtFAwvDqyjOWdztaPdjM-givOWr5tL8Y8cO71pvZnaQa09ueKNNzeKhzVvuSUm_l2xhhA_FfOm8cfTeE26tGtIozKPVfiWbkc4PxKBRLa9qx8CKGFjLeGZQtdjGuBoE2lUr-Version: 3.141.0
Summary: Python bindings for Selenium
Home-page: https://github.com/SeleniumHQ/selenium/ hantomJS has been deprecated, please use headless versions of Chrome or Firefox instead
Author: UNKNOWN
Author-email: UNKNOWN
License: Apache 2.0
Location: e:\py\python3.7\python37\lib\site-packages
Requires: urllib3
Required-by:

2. Solution

1、selenium Version downgrade
2、 adopt python3 -m pip uninstall selenium uninstall , Reinstall the specified version python3 -m pip install selenium==2.48.0
3、 Run again

3. Reference resources

Solution

  1. selenium Version downgrade
  2. adopt pip show selenium Show , The default installation version is 3.8.1.
  3. Unload it pip uninstall selenium, Reinstall and specify the version number pip install selenium==2.48.0.
  4. Run again , Found no error reported , Get it done !
  5. Use a browser without an interface
    Selenium+Headless Firefox
    Selenium+Headless Firefox and Selenium+Firefox, The difference is the instance option When setting -headless Parameters .

Prerequisite :

  • Local installation Firefox browser
  • Local needs geckodriver Drive file , If you do not configure environment variables , Need to be specified manually executable_path Parameters .

Sample code :

from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
def main():
options = Options()
options.add_argument('-headless')
driver = Firefox(executable_path='./geckodriver', firefox_options=options)
driver.get("https://www.qiushibaike.com/8hr/page/1/")
print(driver.page_source)
driver.close()
if __name__ == '__main__':
main()

Selenium+Headless Chrome

And Firefox similar

Prerequisite :

  • Local installation Chrome browser
  • Local needs chromedriver Drive file , If you do not configure environment variables , Need to be specified manually executable_path Parameters .

Example :

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
def main():
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(executable_path='./chromedriver', chrome_options=chrome_options)
driver.get("https://www.baidu.com")
print(driver.page_source)
driver.close()
if __name__ == '__main__':
main()

summary

Share :
Most people who achieve great things are tolerant 、 Bear the mind that people cannot bear , Be good at seeking common ground while reserving minor differences , Unite the majority . They don't haggle over every ounce , Do not dwell on non principled trivia , That's why big things happen , Establish great cause .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved