1 from selenium import webdriver 2 from selenium.webdriver.chrome.options import Options 3 4 5 browers_path = r'C:UsersAdministratorAppDataLocal360ChromeChromeApplication360chrome.exe' 6 chrome_option = Options() 7 chrome_option.binary_location = browers_path 8 browers_driver = webdriver.Chrome(options=chrome_option) 9 browers_driver.get("http://www.baidu.com") 10 browers_driver.execute_script('window.open("https://www.douban.com")') 11 window_list = browers_driver.window_handles#获取窗口列表 12 browers_driver.switch_to.window(window_list[1])#将browers_driver的指针转移到指定的窗口 13 print(browers_driver.current_url)#打印browers_driver指向的窗口网址