1. 好库推荐
https://brucedone.com/archives/1579
pip install webdriver_manager
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://brucedone.com/archives/1579")
2. 无界面 无头
https://www.cnblogs.com/zwnsyw/p/14656820.html
# pip install selenium==3.141.0 from selenium import webdriver import time from selenium.webdriver.chrome.options import Options # 配置的包 path = 'chromedriver.exe' # 配置相关 chrome_options = Options() # 可以理解为配置对象 # 1. 配置不加载图片 # prefs = {"profile.managed_default_content_settings.images": 2} # chrome_options.add_experimental_option("prefs", prefs) # 2. 无界面 # chrome_options.add_argument('--headless') # chrome_options.add_argument('--disable-gpu') # chrome_options.add_argument('--disable-blink-features=AutomationControlled') #重点代码:去掉了webdriver痕迹 # 3. 移动端配置 # WIDTH = 600 # HEIGHT = 800 # PIXEL_RATIO = 3.0 # UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1' # mobileEmulation = {"deviceMetrics": {"width": WIDTH, "height": HEIGHT, "pixelRatio": PIXEL_RATIO}, "userAgent": UA} # chrome_options.add_experimental_option('mobileEmulation', mobileEmulation) # 4. 操作已打开的浏览器 # chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\selenum\AutomationProfile" chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222") browser = webdriver.Chrome(path, options=chrome_options) browser.get('http://www.netbian.com/') time.sleep(15) browser.quit()标签:webdriver,chrome,selenium,--,add,options From: https://www.cnblogs.com/pangniu/p/17434485.html