You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Jon_Jen/README.md

773 B

Jon_Jen

from selenium import webdriver from selenium.webdriver.chrome.options import Options

由于该服务器是在linux上运行没有可视化界面所有我们要使用无头模式

对谷歌浏览器进行设置

chrome_options = Options()

linux上运行时需要以最高权限运行

chrome_options.add_argument('--no-sandbox')

设置无头模式,不打开浏览器窗口

chrome_options.add_argument('--headless')

设置浏览器窗口大小

chrome_options.add_argument('window-size=1920,1080') driver = webdriver.Chrome(executable_path=r'chromedriver', options=chrome_options) #获取chrome浏览器的驱动并启动Chrome浏览器 driver.get('https://www.baidu.com') # 打开百度 print(driver.current_url) # 打印浏览器当前url