浏览器驱动加入环境变量
当前创建 WebDriver 对象,需要指定 ChromDriver 路径, 加入环境变量后可以省略。
把浏览器驱动 所在目录
加入环境变量 Path, 再写代码时,就可以无需指定浏览器驱动路径了,像下面这样 wd = webdriver.Chrome()
关闭 chromedriver 打印信息
from selenium import webdriver
import time
#加上参数,禁止 chromedriver 写屏
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
#可以支持多个参数 1.创建 WebDriver 对象,指明使用chrome浏览器驱动
#2.加上参数,禁止 chromedriver 写屏
wd = webdriver.Chrome(r'c:/chromedriver.exe', options=options)
wd.get('https://www.baidu.com')
#窗口最大化
wd.maximize_window()
#获取当前页面的 标题 URL
print ("title of current page is %s" %(wd.title))
print ("url of current page is %s" %(wd.current_url))
time.sleep(5)
#wd.set_window_size(240,300)
pass