from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
#使用无头谷歌浏览器模式
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
#这个很重要,一定要把沙箱模式禁止,不然会报错
chrome_options.add_argument('--no-sandbox')
#指定谷歌浏览器路径
chrome_options.binary_location = '/opt/google/chrome/chrome'
opener = webdriver.Chrome(chrome_options=chrome_options)
opener.get('https://www.baidu.com')
print(opener.current_url)
opener.quit()
Ubuntu server 18.04 使用 selenium + chrome(--headless模式)
最新推荐文章于 2024-05-07 02:23:33 发布