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 '
翻譯:用戶警告:Selenium對PhantomJS的支持已被棄用,請使用無頭版本的Chrome或Firefox代替
警告。“Selenium對PhantomJS的支持已被棄用,請使用headless”
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:
1、selenium版本降級
2、通過python3 -m pip uninstall selenium卸載,重新安裝指定版本python3 -m pip install selenium==2.48.0
3、再次運行
解決方案
前提條件:
示例代碼:
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
與Firefox類似
前提條件:
示例:
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()
分享:
成大事者大都具有容人所不容、忍人所不忍的心胸,善於求大同存小異,團結大多數人。他們不斤斤計較,不糾纏於非原則性的瑣事,所以才能成大事,立偉業。