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