火狐无头链接 from selenium.webdriver import Firefoxfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.firefox.options import Optionsfrom selenium.webdriver.support import expected_conditions as expectedfrom selenium.webdriver.support.wait import WebDriverWaitif __name__ == "__main__": options = Options() options.add_argument('-headless') # 无头参数 driver = Firefox(executable_path='geckodriver', firefox_options=options) # 配了环境变量第一个参数就可以省了,不然传绝对路径 wait = WebDriverWait(driver, timeout=10) driver.get('http://www.google.com') wait.until(expected.visibility_of_element_located((By.NAME, 'q'))).send_keys('headless firefox' + Keys.ENTER) wait.until(expected.visibility_of_element_located((By.CSS_SELECTOR, '#ires a'))).click() print(driver.page_source) driver.quit()