Skip to content

Instantly share code, notes, and snippets.

@michaelHL
Created August 18, 2018 03:35
Show Gist options
  • Save michaelHL/bc65156a643cb50357fcfea92e54d6c7 to your computer and use it in GitHub Desktop.
Save michaelHL/bc65156a643cb50357fcfea92e54d6c7 to your computer and use it in GitHub Desktop.
Python Selenium 使用非默认路径 Chrome
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import time
chrome_options = Options()
chrome_options.binary_location = 'Chrome/chrome.exe'
webdriver_path = 'Utils/chromedriver.exe'
driver = webdriver.Chrome(
executable_path=webdriver_path,
chrome_options=chrome_options
)
driver.implicitly_wait(3)
driver.get('https://www.baidu.com')
time.sleep(3)
driver.find_element_by_css_selector('map area').click()
time.sleep(1)
# 节假日才会出现
driver.switch_to_window(driver.window_handles[-1])
fest_title = driver.find_element_by_css_selector('div[class$=title]').text
fest_txt = driver.find_element_by_css_selector('div[class$=desc]').text
print(f'{fest_title}: {fest_txt}')
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment