pyhton 采用无头模式不打开浏览器访问网址


import requests
import selenium
import wheel
from selenium import webdriver
from selenium.webdriver.firefox.options import Options as FOptions
from selenium.webdriver.chrome.options import Options as COptions

# driver = webdriver.Chrome(executable_path="D:\PDF\py包\chromedriver_win32\chromedriver.exe")
# driver1 = webdriver.Firefox(executable_path="D:\PDF\py包\geckodriver_win64\geckodriver.exe")

# Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead
# 分手了  可以采用浏览器无头模式   红字是我容易忘记的地方  会导致报错   driver去官网下载即可
# browser = webdriver.PhantomJS(executable_path="D:\PDF\py包\phantomjs\phantomjs.exe")
# browser.get("www.baidu.com")
"""
无头模式
"""
options = COptions()
options.add_argument('-headless')
driver = webdriver.Chrome(executable_path="D:\PDF\py包\chromedriver_win32\chromedriver.exe",
                          chrome_options=options)
driver.get("http://www.sina.com")
print(driver.current_url)

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM