selenium 无头浏览器

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

# 创建一个参数对象,来控制 chrome 浏览器无界面打开
chrome_options = Options()
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--headless')

a = webdriver.Chrome(executable_path=r'D:\python学习\其他\chromedriver.exe', chrome_options=chrome_options)
a.get('http://www.baidu.com') # 访问百度
a.save_screenshot('baidu.png') # 截图测试效果
print(a.page_source)
a.quit()

posted @ 2020-04-01 14:14  我会飞︿( ̄︶ ̄)︿  阅读(164)  评论(0编辑  收藏  举报